Recovering a git reset --soft

允我心安 提交于 2019-12-23 07:27:56

问题


I modified some files in my branch and did a

git add --all

But this added some files that I didn't intend to add for the commit.

So I did a

git reset --soft HEAD~2 (instead of doing git reset HEAD)

But the previous commit was made by someone else and it caused a lot of files to be in modified/added/deleted status. Is there a way to get back to a stage where the only changes I see are the files added/modified by me? Since I didnt make an actual commit, is there a way to move my head back to master without blowing away my changes? git pull is causing merge conflicts as I didn't actually commit my changes.

Thanks!


回答1:


Just do git reset master. This will only update the index and what HEAD points to. It will not modify your work tree files.




回答2:


For future reference, you can review the commits that your behavior causes or leaves behind by calling git reflog , which will include commits that are no longer in your working tree.




回答3:


A visual solution: open git gui:

git gui

At bottom at the Commit Message box choose the radio button labeled Amend Last Commit. You'll see at the left the Staged Changes area. It contains the files you have added in the last commit. Click on the icons of the files you don't want in your commit to remove them from the index. Afterwards just commit again by pressing the Commit button.



来源:https://stackoverflow.com/questions/4589251/recovering-a-git-reset-soft

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!