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