0

I need to revert files from various commits to their previous state.

The reason is we won't deliver a particular functionality in this release.

I have spotted the commits already.

I think cherry-pick and/or rebase is in order but the search results I have confuse me a bit more.

How do I pick an specific version from previous commits in git?

4

2 回答 2

3

如果您只想将单个文件恢复到之前提交中的状态,请使用checkout

git checkout <previous commit SHA> -- /path/to/file

如果要撤消整个提交,请使用revert

git revert <SHA of commit to undo the effects of>
于 2012-04-27T17:19:49.053 回答
0

如果您只是尝试返回到较早状态的一个文件,那么结帐是正确的解决方案

git checkout <sha-1 hash in hex> filename.ext

如果您希望将整个文件夹/提交返回到较早的状态

git revert <sha-1 of commit to reverse>

请注意,使用revertsha-1 哈希是您尝试反转的提交,而不是您尝试恢复的提交,这不是我最初的预期,我一直做错了,当它给出时变得非常沮丧我尝试时出现难以理解的错误消息。

于 2012-04-27T23:23:59.960 回答