我不清楚git如何恢复工作。例如,我想在头之后提交6次,在中间提交的中间恢复所有更改。
假设其SHA哈希值为56e05fced214c44a37759efa2dfc25a65d8ae98d。那我为什么不能这样做
git revert 56e05fced214c44a37759efa2dfc25a65d8ae98d
我不清楚git如何恢复工作。例如,我想在头之后提交6次,在中间提交的中间恢复所有更改。
假设其SHA哈希值为56e05fced214c44a37759efa2dfc25a65d8ae98d。那我为什么不能这样做
git revert 56e05fced214c44a37759efa2dfc25a65d8ae98d
当前回答
这可能有用:
git checkout 56e05f
echo ref: refs/heads/master > .git/HEAD
git commit
其他回答
它将还原所述的提交,即添加与之相反的提交。如果你想签出以前的版本,你可以:
git checkout 56e05fced214c44a37759efa2dfc25a65d8ae98d
回滚到特定提交的最好方法是:
git reset --hard <commit-id>
然后:
git push <reponame> -f
这可能有用:
git checkout 56e05f
echo ref: refs/heads/master > .git/HEAD
git commit
这比较容易理解:
git checkout 56e05fced -- .
git add .
git commit -m 'Revert to 56e05fced'
为了证明它有效:
git diff 56e05fced
如果你的修改已经被推送到一个公共共享的远程,并且你想要还原HEAD和<sha-id>之间的所有提交,那么你可以传递一个提交范围给git revert,
git revert 56e05f..HEAD
并且它将恢复56e05f到HEAD之间的所有提交(不包括范围的起点56e05f)。