5

I would like to remove a specific commit on a git repository in order to be able to remove a "fix" applied to my software.

There it is an EMC :

#!/bin/bash rm -rf TEST .git mkdir TEST git init echo "info 1" > TEST/file.txt git add TEST/ git commit -m "Initial Commit" echo "info 2" >> TEST/file.txt git add TEST/ git commit -m "Commit Fix 1 on file" echo "info 3" >> TEST/file.txt git add TEST/ git commit -m "Commit Fix 2 sur file" 

the result of file.txt will be

info 1 info 2 info 3 

And I would like to obtain the file without the line "info 2". The git revert will generate conflict, and I would like to avoid manage those conflicts. That is to say doing like the commit "Commit Fix 1 on file" would have never append.

I tried revert or rebase without any luke, so if you have another idea, I will be glade to have some help.

Sincerely,

1
  • For what it's worth, kdiff3 was able to handle the "conflict" automatically without any manual intervention. I'm not sure why git can't resolve it automatically.. Commented Oct 8, 2012 at 8:41

2 Answers 2

1

To revert a particular commit, you need to identify the hash of the commit, using git log, then use git revert <commit> to create a new commit that removes these changes.

Sign up to request clarification or add additional context in comments.

3 Comments

The OP mentioned he didn't want to deal with merge conflicts though. I'm not sure why it's a conflict, but it does end up saying "error: could not revert ed0ff67... Commit Fix 1 on file hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' or 'git rm <paths>' hint: and commit the result with 'git commit' "
Exactly, I tried that, but the two last commits acts on the same file. So a git revert lead to a conflict that has to be treated manually. And I need to avoid this manipulation. But you are right if the commits modified two different files ...
@Brownie: it's not that they're introducing changes to the same file, it's that the lines are adjacent in the tiny example file you're using. It's much less likely that there will be such conflicts in a real example.
0
$ git reset HEAD^^ $ change your file to delete the info 2 $ git add . $ git commit -m "Commit Fix 2 sur file" 

1 Comment

Thanks for this answer, but I don't want to manually modify files. The purpose of this is to manage fix on a software and be able to had and remove fixes easily.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.