1

I did commit on my branch.

I accidently added .tar.gz files in it which i want to ignore.

Then i did this

git reset --soft HEAD^

Now my commit is gone

  1. Modified files are as it is
  2. But the untracked files are now being shown as new file

How can i go back to state where the new files come as untrcaked file

Mirage
  • 30,868
  • 62
  • 166
  • 261
  • possible duplicate of [Whats the difference between git reset --mixed, --soft, and --hard?](http://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard) – Oliver Charlesworth Jun 07 '14 at 05:46

3 Answers3

1

A git reset --soft only moves HEAD, but don't reset the index.

A git reset @^ would moves HEAD and reset the index, making those files untracked again.

More on those reset options at "Can you explain what “git reset” does in plain english?".

See also a good illustration in "Difference between git reset soft, mixed and hard": what you want is to reset HEAD and index, not the working tree.

http://davidzych.com/wp-content/uploads/2014/05/reset-wc-changed-580x136.png


The OP user3646965 asks in the comments:

I have already executed git reset --soft, can I do git reset @^ or it will go back one more commit?

Then you can do a reset for the files only (not HEAD, which already references the right commit)

cd /path/to/folder/containing/tar.gz_files
git reset -- *.tar.gz

Note the double-dash (--) between the git command and the files.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • i have already executed `git reset --soft` can i do `git reset @^` or it will go back one more commit – Mirage Jun 07 '14 at 06:11
  • @user3646965 I have edited the answer to address your comment. – VonC Jun 07 '14 at 06:36
  • thanks, but i have tar files in many subdirs not a single folder. will that work if execute in root folder – Mirage Jun 07 '14 at 08:49
  • @user3646965 I don't think it would work recursively. Better to run a classic find command, and pipe its result to a git reset command. – VonC Jun 07 '14 at 08:58
  • thanks Von , Does it mean that there is no way to reset all new files to untracked state from my scenario , . I meean not only tar.gz but is there any way i can untrack all new files from my state – Mirage Jun 07 '14 at 09:11
  • @user3646965 I believe that a simple git reset (from the root folder, no parameters) would be enough to reset everything. – VonC Jun 07 '14 at 09:17
0

You can't actually delete files via a git reset, which means if you've added new files in your recent commit, even if you do, git reset --hard HEAD~1, the files that were added in your last commit won't be deleted. This is an essential and necessary precaution in git. What if, in the hope of restoring your directory to HEAD~1 git accidentally deletes untracked files that were not meant to be deleted?

You can do git reset --hard HEAD~1 to restore the state of the existing files. But if you've added new files in your latest commit, you've to delete it yourself.

tnkousik
  • 103
  • 1
  • 8
0

git reset filename will reset the state of filename to whatever it is at the currently commit — i.e., it will unstage a file.

Eevee
  • 47,412
  • 11
  • 95
  • 127