0

At the HEAD version, I have a mistake that pull another branch when I on master branch so that some new files or directories had been merged into master branch from another. I realize this is a very big mistake. So I use "git reset xxx" to restore into xxx commit version. However, after done command, I really back to xxx commit version and those new files or directories also are there. What's wrong with this action? Whether I take a wrong command? I just want to back to a clean old commit version without any changes by wrong pull action. Thx!

Qinghua
  • 351
  • 3
  • 10

3 Answers3

0

You should use:

git reset --hard xxxx

That would reset the working tree too, in addition of the index.

http://git-scm.com/images/reset/reset-hard.png

(From "Reset Demystified")

Resetting the index only wouldn't get rid of the local modifications done to your working tree.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

To get back to an old commit , discarding all changes:

git reset --hard commit-id

Without the --hard switch you are doing a mixed reset which means that the changes will still be retained in your working set. The --hard switch gets rid of those too.

If you also want to remove any untracked files then:

git clean -f
M.M
  • 138,810
  • 21
  • 208
  • 365
  • "git clean -f -d" works fine, thanks. What's more, why I use "git reset xxx --hard" on windows, the tracked new files or directories in HEAD version change into untracked status in xxx version? – Qinghua Jun 14 '14 at 06:02
  • @xohozu because the right syntax is `git reset --hard xxx`, not `git reset xxx --hard`. – VonC Jun 14 '14 at 06:27
  • @VonC There's no difference between `git reset --hard xxx` and `git reset xxx --hard`. In general, Git allows command line options to show up before or after arguments. Are you seeing a different behavior? – John Szakmeister Jun 14 '14 at 12:34
  • @jszakmeister no, you are right. I had it mixed up with the `` parameter. – VonC Jun 14 '14 at 13:24
  • @xohozu that doesn't happen, new tracked files would be deleted when you reset. If it appears that new untracked files appear , it may be because you are resetting over a change to the .gitignore file – M.M Jun 15 '14 at 00:34
  • @matt-mcnabb you means that windows platform also performs same action, i will check it next time. thanks again. – Qinghua Jun 16 '14 at 02:31
0

Yes, I experienced the same issue, git reset --hard xxxx does not work in Windows git terminal.

This was my response from git terminal:

$ git reset --hard XXXX fatal: ambiguous argument 'XXXX': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'

MT_Shikomba
  • 129
  • 1
  • 6
  • 1
    I meant xxx as a placeholder, which is supposed to be replaced with the commit id you want to reset to. – VonC Nov 20 '20 at 04:26