Reputation:
On a branch I did a few(can't exactly remember how many) git commit
and one git pull
that resulted in a merge failure.
I realized my local changes/commits were just silly, and can be thrown away.
To do that I did:
git checkout master
git branch -D otherbranch
git checkout otherbranch
This seems not to be the correct way of undoing things - what would be the best way ?
Upvotes: 0
Views: 266
Reputation: 8240
Try :
git fetch
git reset --hard origin/<remote_branch>
##this will reset your local branch HEAD to TOT commit
To avoid creating merge commits while git pull, try :
git pull --rebase
normal git pull will create a merge commit if you have local unmerged commits.
Upvotes: 0
Reputation: 8809
If all you want to do is blow away your local changes:
git reset --hard @{u}
Upvotes: 1
Reputation: 841
Look up git rebase
http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html
It allows you to edit your commits as well as remove them.
Upvotes: 0
Reputation: 2019
Undoing in git is done using the reset
command.
Moving back to a known state is typically done using git reset --hard <SHA>
. The SHA is picked from the commit you want to get back to.
Upvotes: 0
Reputation: 182743
You can always do:
git checkout <branch>
git reset --hard <otherbranch>
This changes the branch over to exactly match the state of the other branch.
Upvotes: 3