2013-07-31 211 views
1

假設我們已經提交了AB,而B依賴於A的修改。 我們想恢復A,那會成功嗎?另外,如果由'A'添加的行不再存在,會發生什麼情況?Git根據它恢復一個其他提交的提交

+0

可能重複http://stackoverflow.com/questions/2318777/undo-a-particular-commit-in-git –

+0

可能的重複[如何解決Git合併衝突?](http://stackoverflow.com/questions/161813 /怎麼辦,我修復合併共nflicts-in-git) – bummi

+0

你所要求的僅僅是 - 是否有可能在git歷史中恢復某個提交。 –

回答

7

git會報告回覆導致衝突。 git status將顯示未合併的路徑。

你可以像其他任何resolve the conflict


編輯與例如:

$ 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") 

在這第一次提交添加的文件和的情況下的第二修改的文件,GIT中的狀態將顯示這樣的:

$ 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 
# 
+0

另請參閱http://stackoverflow.com/questions/6084483/what-should-i-do-when-git-revert-aborts-with-an-error-message – onionjake

+0

這也解釋了爲什麼會發生http:// stackoverflow的.com /一個/1049112分之8281946 – onionjake