Let's say we have commit A
and B
, and B
depends on A
's modification.
We want to revert A
, will that be successful? Also, what would happen if a line added by 'A' is no longer present?
Asked
Active
Viewed 263 times
1
-
possible duplicate of http://stackoverflow.com/questions/2318777/undo-a-particular-commit-in-git – kul_mi Jul 31 '13 at 06:19
-
possible duplicate of [How do I fix merge conflicts in Git?](http://stackoverflow.com/questions/161813/how-do-i-fix-merge-conflicts-in-git) – bummi Jul 31 '13 at 13:33
-
What you are asking for is simply - is it possible to revert a certain commit in git history. – kul_mi Jul 31 '13 at 06:24
-
ok I meant something else, dependance is indeed not correct word for that. – kul_mi Jul 31 '13 at 06:26
1 Answers
7
git
will report that the revert resulted in a conflict. git status
will show the unmerged paths.
You can resolve the conflict like any other.
Edit with example:
$ mkdir foo
$ cd foo
$ git init
$ echo "this is a line in a file" > blah
$ echo "this is a second line in a file" >> blah
$ echo "this is a third line in a file" >> blah
$ git add blah
$ git commit -m "first commit"
# edit the second line in blah
$ git commit -am "second commit"
# remove the second line from blah
$ git commit -am "third commit"
$ git revert HEAD^ #revert the second commit
error: could not revert 4862546... another change
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'
$ git status
# On branch master
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add <file>..." to mark resolution)
#
# both modified: blah
#
no changes added to commit (use "git add" and/or "git commit -a")
In the case that the first commit added the file and the second modified that file, git status will show this:
$ git status
# On branch master
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# deleted by them: blah
#
-
Also see http://stackoverflow.com/questions/6084483/what-should-i-do-when-git-revert-aborts-with-an-error-message – onionjake Jul 31 '13 at 06:47