git (sourcetree) 返回未推送且意外“反转”的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17071895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git (sourcetree) go back to commit that has not been pushed and was 'reversed' accidentally
提问by user1282931
I'm still quite new to git revisioning and maybe just lost plenty of work (but I hope there is a way to go back, that's why I'm asking here).
我对 git 修订还是很陌生,也许只是失去了很多工作(但我希望有办法回去,这就是我在这里问的原因)。
I use SourceTree on OsX for git revisioning. I didn't commit for quite a long while and now just wanted to commit plenty of changes. I selected to push immediately after the commit. When the push took very long, I checked my folder and noticed that I accidentally had selected a big build folder that should not be checked in. So I cancelled the push (I got a message something like commit was successful but push was not).
我在 OSX 上使用 SourceTree 进行 git 修订。我有很长一段时间没有提交,现在只想提交大量更改。我选择在提交后立即推送。当推送需要很长时间时,我检查了我的文件夹,注意到我不小心选择了一个不应该被签入的大构建文件夹。所以我取消了推送(我收到一条消息,比如提交成功但推送没有)。
So, even though I interrupted the push, I still saw this commit in my master branch. I wanted to undo this, so I could commit again (this time without the build folder). I rightclicked on the commit and there was a 'Reverse commit...' option, which I clicked. But instead of removing this revision, it added another revision labeled 'Revert "Name of the commit i wanted to undo"'.
所以,即使我中断了推送,我仍然在我的主分支中看到了这个提交。我想撤销这个,所以我可以再次提交(这次没有构建文件夹)。我右键单击提交,然后单击了一个“反向提交...”选项。但它没有删除此修订版,而是添加了另一个标记为“还原“我想撤消的提交的名称””的修订版。
Bad thing is - now all my local changes seem to have gone and my files are on the state from one month ago.
坏事是 - 现在我所有的本地更改似乎都消失了,而且我的文件从一个月前开始保存在状态中。
since the commit (of which I cancelled the push) is still in the list, I wonder if I can somehow go back there? Is there any chance to get the local changes I made during last month back? I do have a backup of my files, but that's also almost two weeks old.
由于提交(我取消了推送)仍在列表中,我想知道我是否可以以某种方式回到那里?有没有机会让我在上个月所做的本地更改回来?我确实有我的文件的备份,但这也差不多两个星期了。
This is how sourcetree currently looks like:
这是 sourcetree 目前的样子:
as you can see, the previous successful commit/push i made was on may 20. Then today I tried to commit/push new features, but interrupted during pushing. Then i 'reversed' this (interrupted) commit, which aparently reset all my local files to the state from may 20. Sourcetree shows that there are 2 Pushs to make (which I assume are the interrupted push and the push for the 'reverse' commit).
如您所见,我之前成功的提交/推送是在 5 月 20 日。然后今天我尝试提交/推送新功能,但在推送过程中被中断。然后我“逆转”了这个(中断的)提交,这显然将我所有的本地文件重置为 5 月 20 日的状态。Sourcetree 显示有 2 个推送(我假设是中断推送和“反向”推送犯罪)。
Is there any way I can go back to my local state I had right before committing today?
我有什么办法可以回到我今天提交之前的当地状态吗?
Thank you so much
非常感谢
回答by Klas Mellbourn
First undo the revertcommit, throwing away the changes it created:
首先撤消还原提交,丢弃它创建的更改:
git reset --hard HEAD^
Then undo the updated render graphicscommit, but keep those changes in your working tree (your local files):
然后撤消更新的渲染图形提交,但将这些更改保留在您的工作树(您的本地文件)中:
git reset HEAD^