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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 19, 2014 at 09:12:47PM +0630, Arup Rakshit wrote:

> Is there any difference between the below 2 commands ? I didn't see anything.
> 
> git rm --cached  -- <file1> .. <fileN>

This one removes the index entries for those files.

> git checkout  -- <file1> .. <fileN>

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

Try:

  # setup...
  git init
  echo content >file
  git add file
  git commit -m one

  # now rm
  git rm --cached -- file
  git status

which yields:

  rm 'file'

  On branch master
  Changes to be committed:
          deleted:    file
  
  Untracked files:
          file
  

but it we restore our state and try checkout:

  git reset
  git checkout -- file

nothing happens:

  On branch master
  nothing to commit, working directory clean

but if you had changes in the working tree:

  echo changes >file
  git status | sed 's/^/before> /'
  git checkout -- file
  git status | sed 's/^/ after> /'

you get:

  before> On branch master
  before> Changes not staged for commit:
  before>         modified:   file
  before> 
  before> no changes added to commit

   after> On branch master
   after> nothing to commit, working directory clean

Does that help?

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]