即使状态是干净的,Git恢复也会失败

时间:2016-06-14 06:17:32

标签: git version-control

我对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

我仍然不明白为什么我得到一个git revert错误

1 个答案:

答案 0 :(得分:4)

因为在提交1af755中你创建了2.txt,恢复提交意味着文件被删除。但是,在该提交之后,您已经修改了文件2.txt,并且这些更改与删除该文件冲突。因此,您会遇到冲突,需要手动解决。