标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:How do I undo the most recent commits in Git?78 answersBy mistake, I did git add . and git commit in the develop branch. But luckily, I did not do git push.So I wanted to revert it back to original state.I tried git reset --soft and git reset HEAD --hard but looks like I have messed it up.How do I fix this? I want to go back to original state and possibly keep the code changes.


plus one for the yet

2019年03月27日13分25秒

This might be a duplicate, but this is the over simplistic answer that I want 90% of the time. Thank you

2019年03月27日13分25秒

After you do this, if you want to completely remove the unstaged changes, you'll need to run the following:git reset --hard HEAD

2019年03月26日13分25秒

Don't know why this answer marked as correct. I get error thrown fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, Doesn't work

2019年03月26日13分25秒

On windows, the caret is a special character for CMD (it's used to escape a character, similar to the backslash in Linux) so you better quote "HEAD^".

2019年03月27日13分25秒

fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. Use '--' to separate paths from revisions

2019年03月26日13分25秒

Try using git bash. If you're using Windows the console won't work for some reason, not sure why. Git bash does tho.

2019年03月26日13分25秒

Green Windows doesn't like HEAD~1, wrap it in quotes like git reset --soft "HEAD~1"

2019年03月26日13分25秒