top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Any difference to unstage files using "git checkout" and "git rm"

+1 vote
638 views

Is there any difference between the below three commands ? I didn't see anything.

git rm --cached --  .. 
git checkout --  .. 
git reset HEAD --  .. 
posted May 19, 2014 by Sanketi Garg

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

git rm --cached -- ..

This one removes the index entries for those files.

git checkout -- ..

This one checks out the content from the index into the working tree (for just those files).

git reset HEAD -- ..
The first command will remove the entries from the index entirely, and this one will return them to their state in HEAD. So if the existing commit in HEAD did not have the files at all, the this is identical to the first one.

answer May 19, 2014 by Kaushik
Similar Questions
+1 vote

I wanted to avoid push if any of the files is deleted from the local git clone area. Can anyone please help me with that?

I am using Stash for repository management.

+2 votes

As you know, I can checkout the Nth checked out branch via this syntax:

$ git checkout @{-N}

Is there a built-in mechanism to get a listing of previously checked out refs? Basically, this would be similar to 'history' command in linux where instead of actual commands, it lists like this:

HEAD@{-1}: master
HEAD@{-2}: topic1
HEAD@{-3}: 3f346e9 (detached)

Seems like reflog should be able to do this, and maybe it can, but I'm not sure. Any tips? I'd be fine making a convenient alias for this if it ends up being a series of piped commands.

+1 vote

Running on Windows with latest version of Git. 1.9.4. Also had this trouble with 1.8.2 but upgraded hoping it would fix the problem.

When I do a reset on several files, it says they were successfully reverted they still show up as modified when I do a git status. In this case it's just a newline character at the end of the file. I also tried a reset -- hard and they files still show up! What the heck! Help please.

In trying to reproduce this, I re-cloned the git repo from the server, which was in the exact clean state before I started last time. No files have been modified after cloning, all are identical. Then, I created a new branch (totally new, not tracking a remote branch). Viola - I now have these files show up in my git status as modified. Please note that these are files that have been tracked for several previous commits.

Just to clarify - the only command I ran to make this happen is: git checkout -b newbranch

And GitGui shows the files as identical even when compare whitespace is turned on.

...