如何在git中恢复提交?

时间:2014-04-15 19:47:00

标签: git revert

我想还原一个提交,其中我修改了文件并添加了文件:

mkdir repo_1
cd    repo_1
git   init

echo Version one>      a.txt
echo Version one>      b.txt

git add    a.txt b.txt      
git commit a.txt b.txt             -m "V.1"

echo Version two>>     a.txt
echo Version two>>     b.txt
echo Version two>>     c.txt

git add    c.txt

git commit a.txt b.txt c.txt       -m "V.2"

echo Version three>>   a.txt
echo Version three>>   b.txt
echo Version three>>   c.txt


git commit a.txt b.txt c.txt       -m "V.3"

完成这些步骤后,git log .打印

commit fdd97fc23535107202732888b240bbe2e4e08554
Author: Some One <some.one@somewhe.re>
Date:   Tue Apr 15 21:40:04 2014 +0200

    V.3

commit 8cab1785c5d653b4965045a1f77cf909c6ed4ddc
Author: Some One <some.one@somewhe.re>
Date:   Tue Apr 15 21:40:04 2014 +0200

    V.2

commit 2eb9d1561a696856beaa49c3d839863ed279a8e5
Author: Some One <some.one@somewhe.re>
Date:   Tue Apr 15 21:40:04 2014 +0200

    V.1

现在,我想取消我对V.2提交的更改,即使用SHA 8cab1785c5d653b4965045a1f77cf909c6ed4ddc

当我尝试git revert 8cab1785c5d653b4965045a1f77cf909c6ed4ddc时,我得到了一个

error: could not revert 8cab178... V.2
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 revert -n 2eb9d1561a696856beaa49c3d839863ed279a8e5 8cab1785c5d653b4965045a1f77cf909c6ed4ddc时,我得到了一个

error: could not revert 2eb9d15... V.1
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'

那么,如何恢复我的第二次提交呢?

0 个答案:

没有答案