git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* checkout from neighbour branch  undeletes a path?
@ 2012-11-13 15:23 Peter Vereshagin
  2012-11-13 16:43 ` Junio C Hamano
  2012-11-13 23:41 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Vereshagin @ 2012-11-13 15:23 UTC (permalink / raw)
  To: git

Hello.

Am wondering if 'checkout branch path' undeletes the files? For the example
below I'd like the 'file00.txt' to be deleted and never checked out from the
previous branch... How can I do that?

  $ git init                                                                                             
  Initialized empty Git repository in /tmp/repo00/.git/
  $ mkdir pathdir
  $ echo test00 > pathdir/file00.txt
  $ git add pathdir
  $ git commit -am 'added file00.txt'
  [master (root-commit) d4f7c70] added file00.txt
   1 files changed, 1 insertions(+), 0 deletions(-)
   create mode 100644 pathdir/file00.txt
  $ git branch -m master branch00
  $ git branch branch01
  $ rm pathdir/file00.txt
  $ echo test01 > pathdir/file01.txt
  $ git add pathdir
  $ git status
  $ git commit -am 'added file01.txt; removed file00.txt'
  [branch00 c3e78ff] added file01.txt; removed file00.txt
   2 files changed, 1 insertions(+), 1 deletions(-)
   delete mode 100644 pathdir/file00.txt
   create mode 100644 pathdir/file01.txt
  $ git checkout branch01
  Switched to branch 'branch01'
  $ rm -r pathdir
  $ git checkout branch00 pathdir
  $ find pathdir/
  pathdir/
  pathdir/file00.txt
  pathdir/file01.txt
  $

I know about 'merge' and it's not the what I need:  to import only the
particular subdirectory from the previous branch.

Thank you.

--
Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checkout from neighbour branch  undeletes a path?
  2012-11-13 15:23 checkout from neighbour branch undeletes a path? Peter Vereshagin
@ 2012-11-13 16:43 ` Junio C Hamano
  2012-11-13 18:34   ` Peter Vereshagin
  2012-11-13 23:41 ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2012-11-13 16:43 UTC (permalink / raw)
  To: Peter Vereshagin; +Cc: git

Peter Vereshagin <peter@vereshagin.org> writes:

> Am wondering if 'checkout branch path' undeletes the files?

"git checkout branch path" (by the way, "branch" does not have to be
a branch name; any commit object name would do, like "git checkout
HEAD^^ hello.c") is a way to check out named path(s) out of the
named commit.

If the commit "branch" has "path" in it, its contents are checked
out to "path" in your current working tree (and the entry in the
index updated to match it).

If you happen to have removed "path" in your current working tree
before running that command, it might look as if there is some
undelete going on, but that is a wrong way to look at things.  The
version of "path" in the "branch" may or may not be similar to what
you have removed earlier.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checkout from neighbour branch  undeletes a path?
  2012-11-13 16:43 ` Junio C Hamano
@ 2012-11-13 18:34   ` Peter Vereshagin
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Vereshagin @ 2012-11-13 18:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Peter Vereshagin, git

Hello.

2012/11/13 08:43:31 -0800 Junio C Hamano <gitster@pobox.com> => To Peter Vereshagin :
JCH> Peter Vereshagin <peter@vereshagin.org> writes:
JCH> 
JCH> > Am wondering if 'checkout branch path' undeletes the files?
JCH> 
JCH> "git checkout branch path" (by the way, "branch" does not have to be
JCH> a branch name; any commit object name would do, like "git checkout
JCH> HEAD^^ hello.c") is a way to check out named path(s) out of the
JCH> named commit.
JCH> 
JCH> If the commit "branch" has "path" in it, its contents are checked
JCH> out to "path" in your current working tree (and the entry in the
JCH> index updated to match it).
JCH> 
JCH> If you happen to have removed "path" in your current working tree
JCH> before running that command, it might look as if there is some
JCH> undelete going on, but that is a wrong way to look at things.  The
JCH> version of "path" in the "branch" may or may not be similar to what
JCH> you have removed earlier.
JCH> 


Hello.

I solved my problem by mean of 'git rm' instead of 'rm'.

I knew what you said here. Shortly, the difference for my case was:

 - I check out the pathdir from the commit in which the pathdir/file00 was
   already removed.

 - The current branch 'branch01' has no idea the file00 was removed. But I
   removed file00 and this is what 'branch01' assumes when I commit n ext time.

But git assumes I need 'file00' although it doesn't exist in the commit I
checkout path from. It doesn't exist by itself before I checkout that path
neither.

How can I know which one of the 'file00' versions is being checked out: the one
that did exist in the 'branch00' (the where I checkout path from) before I
removed it or the one existing in HEAD but not in the work-tree? And why this
and not that?

If it is the one that exists in a current branch but was deleted from trhe
work-tree [d4f7c70] than why it is being checked out not from the commit
supplied as an argument to git?

If it is the one that existed [c3e78ff] before the commit I checkout path from
than why it is being checked out while it doesn't exist in that commit already?

Thank you.

--
Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checkout from neighbour branch  undeletes a path?
  2012-11-13 15:23 checkout from neighbour branch undeletes a path? Peter Vereshagin
  2012-11-13 16:43 ` Junio C Hamano
@ 2012-11-13 23:41 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2012-11-13 23:41 UTC (permalink / raw)
  To: Peter Vereshagin; +Cc: git

Peter Vereshagin <peter@vereshagin.org> writes:

>   $ rm -r pathdir
>   $ git checkout branch00 pathdir
>   $ find pathdir/
>   pathdir/
>   pathdir/file00.txt
>   pathdir/file01.txt
>   $

Hasn't this been fixed at 0a1283b (checkout $tree $path: do not
clobber local changes in $path not in $tree, 2011-09-30)?

Are you using 1.7.7.1 or newer?  If not, please upgrade.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-13 23:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-13 15:23 checkout from neighbour branch undeletes a path? Peter Vereshagin
2012-11-13 16:43 ` Junio C Hamano
2012-11-13 18:34   ` Peter Vereshagin
2012-11-13 23:41 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).