[英]How to go back to previous uncomitted state after git pull
I am working on a feature-branch
alongside with my colleague. 我正在与同事一起进行feature-branch
。 It's been a few days that I that have committed
my changes. 它一直是我已经几天committed
我的变化。
Yesterday he has committed his changes and that changed the structure of the project we were working on but didn't harm my changes. 昨天他进行了更改,这更改了我们正在研究的项目的结构,但没有损害我的更改。
I have pulled those changes and made a commit with mine.Upon testing later I realized its not working the way I want it to be, so I want to go back to the state before that pull. 我已经撤消了这些更改并向我的提交了一次提交。在测试之后,我意识到它并没有按照我希望的方式工作,因此我想回到撤消之前的状态。
I cannot go back to my previous commit since by doing that my latest changes will be lost. 我不能回到以前的提交,因为这样做会使我最近的更改丢失。
I tried git reflog
which show me this output : 我尝试了git reflog
,它向我显示此输出:
08aed28 HEAD@{0}: commit: Added support for database
4cf0fe8 HEAD@{1}: pull: Fast-forward
d5e2930 HEAD@{2}: commit: Added logs
I did git reset --hard HEAD@{1}
but that will not take me to previous state. 我做了git reset --hard HEAD@{1}
但这不会使我回到以前的状态。
What should I do ? 我该怎么办 ?
To continue working with your changes on a older commit I would suggest you the following chain of commands - I'll assume you are using the command line interface. 要继续在较旧的提交上进行更改,我建议您使用以下命令链-我假设您正在使用命令行界面。
123abc
) 找到您要“开始”工作的提交(假设提交哈希为123abc
) test
) - git branch test 123abc
创建一个指向该提交的分支(我们称其为test
) git branch test 123abc
git checkout test
检查新分支git checkout test
git checkout -b test 123abc
) (您可以通过使用git checkout -b test 123abc
结合这两个步骤) git cherry-pick
to regain your new changes 使用git cherry-pick
重新获得新的更改 cherry-pick ( documentation ) 樱桃摘 ( 文档 )
You can use cherry-pick
to (quote documentation) " Apply the changes introduced by some existing commits ". 您可以使用cherry-pick
(引用文档)“ 应用一些现有提交所引入的更改 ”。
In your case you could now simply use a command similar to this one: git cherry-pick 456def
(where 456def
is the hash of the commit whose changes you want to apply). 在您的情况下,您现在可以简单地使用类似于以下命令的命令: git cherry-pick 456def
(其中456def
是要应用其更改的提交的哈希)。
It's also possible to cherry-pick
a range of commits, if you for example want to pick the latest 3 commits from the master branch your command could look like this git cherry-pick master~3..
. 也有可能cherry-pick
一系列提交,例如,如果您想从master分支中选择最新的3个提交,您的命令可能类似于git cherry-pick master~3..
For further information on take a look at the gitrevisions
documentation or alternativly the Revision Selection chapter of the progit book . 有关更多信息,请参阅gitrevisions
文档,或者替代progit书中的“ 版本选择”一章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.