Quantcast
Viewing latest article 28
Browse Latest Browse All 42

Answer by blak3r for How do I discard unstaged changes in Git?

I really found this article helpful for explaining when to use what command: http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/

There are a couple different cases:

  1. If you haven't staged the file, then you use git checkout. Checkout "updates files in the working tree to match the version in the index". If the files have not been staged (aka added to the index)... this command will essentially revert the files to what your last commit was.

    git checkout -- foo.txt

  2. If you have staged the file, then use git reset. Reset changes the index to match a commit.

    git reset -- foo.txt

I suspect that using git stash is a popular choice since it's a little less dangerous. You can always go back to it if you accidently blow too much away when using git reset. Reset is recursive by default.

Take a look at the article above for further advice.


Viewing latest article 28
Browse Latest Browse All 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>