Possible Duplicate:
Git undo last commit
I have a folder structure like this..
~/git
......all repos of my github account
.....play
.....emacs.d
.....dummy
.....etc
i have created dummy repo to get familiar with git commands.
so instead of initializing dummy folder,i have issued git init
in git folder and
issued git add .
,and committed to my local repo.
I want to go back to my previous state,and do not want to loose any changes i have done. How can i do that?
Removing the last commit To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
When you save and exit the editor, Git applies all two changes and then puts you back into the editor to merge the three commit messages: # This is a combination of commits. # The first commit's message is: Removed most clearfixs in templates # This is the 2nd commit message: Removed most clearfixs in templates.
The reason why you should use cherry-pick rarely is that it easily creates "duplicate" commits: when you integrate a commit into your HEAD branch using cherry-pick, Git has to create a new commit with the exact same contents. It is, however, a completely new commit object with its own, new SHA identifier.
I assume your ~/git folder was no git repo before? Simply delete the .git folder and everything is like it was before.
All repos (play, emacs.d etc) still have their individual .git folders and are complete repos..
The only thing you did was init another git repo that is now also tracking the other repositories (including their .git folder contents)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With