2016-06-14 70 views
-1

我對git非常陌生,我正在探索git。即使狀態很乾淨,Git還原失敗

這是我輸入的命令鏈。

C:\Users\User\Documents\GitHub> cd test 
C:\Users\User\Documents\GitHub\test> git init 
Initialized empty Git repository in C:/Users/User/Documents/GitHub/test/.git/ 
C:\Users\User\Documents\GitHub\test [master]> touch 2.txt 
C:\Users\User\Documents\GitHub\test [master +1 ~0 -0 !]> git add . 
C:\Users\User\Documents\GitHub\test [master +1 ~0 -0]> git commit -a 
[master (root-commit) 1af7554] init commit 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 2.txt 
C:\Users\User\Documents\GitHub\test [master]> notepad .\2.txt 
C:\Users\User\Documents\GitHub\test [master]> git status 
On branch master 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     modified: 2.txt 

no changes added to commit (use "git add" and/or "git commit -a") 
C:\Users\User\Documents\GitHub\test [master +0 ~1 -0]> git add . 
C:\Users\User\Documents\GitHub\test [master +0 ~1 -0]> git commit -m "changed file 2" 
[master 494394c] changed file 2 
1 file changed, 1 insertion(+) 
C:\Users\User\Documents\GitHub\test [master]> git log 
commit 494394c1c4b5131526ad5137febba54442211303 
Author: email 
Date: Tue Jun 14 14:15:37 2016 +0800 

    changed file 2 

commit 1af755406aad60fb014c496548ea198d59a1af52 
Author: email 
Date: Tue Jun 14 14:15:10 2016 +0800 

    init commit 
C:\Users\User\Documents\GitHub\test [master]> git revert 1af755 
error: could not revert 1af7554... init commit 
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' 
C:\Users\User\Documents\GitHub\test [master +0 ~0 -0 !1 | +0 ~0 -1]> 3b0c5670 

我還是不明白,爲什麼我得到一個混帳復歸錯誤

+0

494394是依賴於1af755的提交。您不能僅恢復1af755。當您恢復1af755時,2.txt將被刪除。但是494394需要該文件存在。所以有衝突。您必須決定是保留還是刪除文件。 – ElpieKay

回答

4

因爲在提交1af755創建2.txt,恢復提交將意味着該文件被刪除。但是,在提交之後,您已經修改了文件2.txt,並且這些更改與刪除該文件相沖突。因此,您遇到了需要手動解決的衝突。

+0

嗨,請建議我如何解決它。我在commit 1af755創建了該文件,但這也意味着如果我恢復到此提交。我會得到這個原始狀態的文件 – aceminer

+1

我認爲你誤解了'git revert'的作用,而你想要做的是'git reset'。查看以下兩個文檔的相關文檔:https://git-scm.com/docs/git-revert和https://git-scm.com/docs/git-reset – 1615903

+0

如果您想解決手頭的衝突,請參閱http://stackoverflow.com/q/161813/1615903 – 1615903