0

I've seen How do I force "git pull" to overwrite local files? but git fetch -all; git reset --hard origin/master will reverts to the latest commit.

My question is :

I checked out into a previous commit, then I made some modifications to the local files. Now, I want to revert all the local changes but stay in that commit. What is the command ?

(Of course I know I can do 'git checkout' for all the modified files but there should be a couple of commands).

LeGEC
  • 46,477
  • 5
  • 57
  • 104
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • 2
    You mean `git reset --hard HEAD`? It will undo everything that isn't in the currently checked out commit. – matt Aug 04 '22 at 00:36
  • Ah! that was it. (I realized how to use HEAD now..). If you make your comment as an aswer, I can selete it. Thank you! – Chan Kim Aug 04 '22 at 01:21
  • 2
    No thanks, this seems trivial, almost tautological. As you rightly imply, it is simply an expression of what "HEAD" means. Note that you could omit saying `HEAD` here, as it is implicit; I usually just say `git reset --hard` plain and simple. – matt Aug 04 '22 at 01:23
  • One more solution is `git restore .`, or probably `git checkout .` will do the same – Bogdan Onischenko Aug 04 '22 at 01:32
  • Side note: you almost never want to use `git fetch --all` (which has two dashes, not one). – torek Aug 04 '22 at 09:55

0 Answers0