Git: How do I checkout a branch ignoring all local changes?

15,499

Solution 1

http://linux.die.net/man/1/git-reset

git reset --hard

Solution 2

git reset --hard

If you want a visual representation of the Branches and commits first type

gitk

Right-click on the desired previous commit and click on "Reset branch to here" You will be presented with 3 options

Use HARD : to discard all the local changes

OR

Use MIXED: to keep the local changed incase if you want to commit again, and it resets the index to the previous commit

Share:
15,499
ScottCate
Author by

ScottCate

Updated on June 04, 2022

Comments

  • ScottCate
    ScottCate almost 2 years

    After I have messed around with directories (created/removed) and added/edited both text and binary files, how do I tell git to throw away all my changes, and bring the branch down again, as if I never messed with anything?

    Currently I'm doing these two commands.

    git stash
    git stash clear
    git pull <remote> <branch>
    

    which seems to work. I read in help that -f is used to throw away local changes. If that's the case does ...

    git checkout <branch> -f
    

    do the same thing?

    Thank you!

  • ScottCate
    ScottCate about 12 years
    this wasn't working, but after paying more attn to the documentation, it's because the files and dir's weren't being tracked. so first ... git add ., then I could git reset --hard