From: "Björn Steinbrink" <B.Steinbrink@gmx.de>
To: Jonathan Wills <runningwild@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, Zabre <427@free.fr>,
git@vger.kernel.org
Subject: Re: (beginner) git rm
Date: Thu, 29 Jan 2009 03:34:32 +0100 [thread overview]
Message-ID: <20090129023432.GF7503@atjola.homenet> (raw)
In-Reply-To: <6bef44ba0901281711m2d05e70fj4dd3ae03d7fe1052@mail.gmail.com>
On 2009.01.28 17:11:07 -0800, Jonathan Wills wrote:
> This seems like an appropriate thread to ask something I came across today.
> Either I am unclear about the precise semantics of git checkout <branch>
> <path>, or there is a bug in said command. I noticed this when I wanted to
> get a directory to match the same directory in another branch, so I did rm
> -rf dir, followed by git checkout master dir. Afterwards I noticed that
> files in that directory that had previously been in my branch but were not
> in the master branch had returned. Earlier in this thread it was mentioned
> that git checkout will not remove files, but in this case I had already
> removed those files and git checkout actually replaced them (and not from
> the master branch like I asked, but from the current branch).
This is exactly what I meant. Your "rm -rf dir" only removed the
directory from the working tree, but _not_ from the index. And what
"git checkout master -- dir" then does is that it puts all the stuff
that is in master's "dir" into the index, in _addition_ to the stuff
already in the index. And then it puts everything from the index's "dir"
into the working tree. This is really a two step process and in each
step the pathspec is matched separately.
So the working tree doesn't have "dir" at all.
In the index you still have:
whatever
dir/file (index version)
dir/other_file
In master you have:
whatever_2
dir/file (master version)
dir/yet_another_file
Then you do "git checkout master -- dir".
In the first step, that "dir" pathspec matches these files from master:
dir/file
dir/yet_another_file
So those are added to the index, and the index will have:
whatever
dir/file (master version)
dir/other_file
dir/yet_another_file
So "dir/file" was replaced, and "dir/yet_another_file" was added. But
"dir/other_file" is still around.
And then comes the index -> working tree step. The pathspec matches all
three files in "dir" in the index, and so they appear in the working
tree.
To get what you expected, you have several options:
a)
rm -rf dir
git add -u dir (drops it from the index)
git checkout master -- dir
b)
git rm -rf dir
git checkout master -- dir
Just saves the "git add -u" step.
c)
rm -rf dir
git reset master -- dir
git checkout -- dir
The reset makes "dir" in the index equal to master's "dir" (ok,
technically that's wrong, as the index doesn't even know about "dir" on
its own, but my brain fails to produce a correct description).
Björn
prev parent reply other threads:[~2009-01-29 2:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-28 10:11 (beginner) git rm Zabre
2009-01-28 10:36 ` Peter Krefting
2009-01-28 11:05 ` Zabre
2009-01-28 11:37 ` Tomas Carnecky
2009-01-28 12:00 ` Zabre
2009-01-28 12:19 ` Tomas Carnecky
2009-01-28 13:03 ` Theodore Tso
2009-01-28 18:25 ` Zabre
2009-01-28 18:23 ` Zabre
2009-01-28 20:17 ` Björn Steinbrink
2009-01-28 20:42 ` Zabre
2009-01-28 21:05 ` Zabre
2009-01-28 21:29 ` Junio C Hamano
2009-01-28 22:13 ` Björn Steinbrink
2009-01-28 22:33 ` Junio C Hamano
[not found] ` <6bef44ba0901281711m2d05e70fj4dd3ae03d7fe1052@mail.gmail.com>
2009-01-29 2:34 ` Björn Steinbrink [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090129023432.GF7503@atjola.homenet \
--to=b.steinbrink@gmx.de \
--cc=427@free.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=runningwild@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox