user964970
user964970

Reputation:

git, get rid of local commits / restore branch to upstream

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

Answers (5)

mrutyunjay
mrutyunjay

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

cforbish
cforbish

Reputation: 8809

If all you want to do is blow away your local changes:

git reset --hard @{u}

Upvotes: 1

tomato
tomato

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

HonkyTonk
HonkyTonk

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

David Schwartz
David Schwartz

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

Related Questions