0

I want to reset Git repository to state from some other commit (have in my working directory only the files from that commit and in versions from that commit), but I don't want to move HEAD of the branch (which would be done by git reset), leave all the commit history intact.

What is the way to do that?

Robert Kusznier
  • 6,471
  • 9
  • 50
  • 71
  • I don't know if git can do that. You could use git diff to make a patch file, then apply that in the normal way, not using git. – Paul Hicks Oct 19 '17 at 08:23

1 Answers1

2

WARNING THIS WILL DELETE UNTRACKED FILES AND DISCARD ALL CHANGES but that’s what you asked for:

have in my working directory only the files from that commit

Delete tracked files (don’t forget the git in front of this, rm -rf . is quite different):

git rm -rf .

Delete untracked files, including ignored ones:

git clean -fdx

(There is only .git now)

Check out the files from the revision you want without checking out the revision itself:

git checkout some-other-commit -- .
Ry-
  • 218,210
  • 55
  • 464
  • 476