git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
May 19, 2014, 16:01 UTC
Message-ID
<20140519160107.GE20289@sigill.intra.peff.net>
In-Reply-To
<6833494.47nikG189t@linux-wzza.site>
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
Previous: Jeff KingNext: Arup Rakshit
Message 4 of 5 in “Any difference to unstage files using "git checkout" and "git rm"”
  1. Arup RakshitMay 19, 2014
  2. Arup RakshitMay 19, 2014
  3. Jeff KingMay 19, 2014
  4. Jeff KingMay 19, 2014
  5. Arup RakshitMay 19, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.