Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-19 Thread Konstantin Khomoutov
On Tue, 18 Dec 2012 21:24:03 -0500
wor...@alum.mit.edu (Dale R. Worley) wrote:

[...]
 |   git-blame - Show what revision and author last modified each
 | line of a file
 
 That's great! ... But the existence of git-blame means that git can,
 *in practice*, trace the history of an individual file, and even
 individual lines within a file.

True, but your choice of the word trace is actually very precise, and
that's what I was talking about in my previous mails in this thread:
Git does not *explicitly* record histories of individual files.
Instead, a line of history in Git is just a series of snapshots of the
repository state linked together to form the parent(s)-child
relationship.  Each snapshot in this graph is completely unaware about
which files are contained in its parent snapshot(s).
Hence, like with `git log`, `git blame` traverses the chain of commits,
considering each commit and applying its heuristics to detect file
renames.

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-19 Thread Dale R. Worley
 From: Konstantin Khomoutov flatw...@users.sourceforge.net
 
  That's great! ... But the existence of git-blame means that git can,
  *in practice*, trace the history of an individual file, and even
  individual lines within a file.
 
 True, but your choice of the word trace is actually very precise, and
 that's what I was talking about in my previous mails in this thread:
 Git does not *explicitly* record histories of individual files.

What I mean by trace is able to provide the history of.  How Git
organizes its repository is not interesting to me; what information
Git can provide me is.  Like any software, Git could reorganize its
internal structure in the next revision, and as long as all the
commands continued to deliver the same information to me, it doesn't
matter to me.

Dale

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Dale R. Worley
 From: Konstantin Khomoutov flatw...@users.sourceforge.net
 
 In general, it's impossible to copy a file from one branch to another,
 preserving its history.

It must be *possible* to do that:  You could do a merge between the
head of A and the head of B, where all of the files of A are carried
into the merged version, and only the one file of B is carried into
the merged version.  The question is how to do that without needing
1,000 commands.

Dale

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread John McKown
What about something like the following (on Linux)

git checkout -b newbranch
git ls-files | fgrep -v 'file.to.keep' | while read i;do git rm $i;done
# newbranch now only contains file.to.keep
git checkout B
git merge newbranch
git -d newbranch

I'm not too sure about this. I'm still too new at git to be sure of the 
git ls-files doing what I think.

On Tuesday, December 18, 2012 9:37:47 AM UTC-6, Dale Worley wrote:

  From: Konstantin Khomoutov flat...@users.sourceforge.net javascript: 

  
  In general, it's impossible to copy a file from one branch to another, 
  preserving its history. 

 It must be *possible* to do that:  You could do a merge between the 
 head of A and the head of B, where all of the files of A are carried 
 into the merged version, and only the one file of B is carried into 
 the merged version.  The question is how to do that without needing 
 1,000 commands. 

 Dale 


-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Konstantin Khomoutov
On Tue, 18 Dec 2012 10:37:47 -0500
wor...@alum.mit.edu (Dale R. Worley) wrote:

  In general, it's impossible to copy a file from one branch to
  another, preserving its history.
 
 It must be *possible* to do that:  You could do a merge between the
 head of A and the head of B, where all of the files of A are carried
 into the merged version, and only the one file of B is carried into
 the merged version.  The question is how to do that without needing
 1,000 commands.

What I meant, is that in certain VCS, namely Subversion,
the history of any given file is *implemented* -- both as a
concept and physically.
I mean, `svn cp branch1/filename branch2/filename` would copy only that
one file from branch1 to branch2, and its (full) history will still be
traceable from its new copy in branch2.

Since Git only records snapshots of whole trees and does not really
track individual files, there's no such *concept* as the history of an
individual file -- it might appear to exist (thanks to the
`git log ... filename` command) but it's implemented as a filter
applied to the regular line of history plus the trickery named rename
detection which uses heuristics (controlled by certain knobs).

So yes, it's possible to invent hacks to take a branch, rewrite each
commit on it to only leave that single file in them and then merge that
line of history to the target branch, but they will still remain hacks.

And there's more to it, actually.  Inability to copy a file with its
full history between branches was my pet peeve when I were starting
with Git (and my first question to this list was about this, by the
way).  But later, when I got accustomed to the model of snapshots
exercised by most (if not all) DVCSes that pet hate was seriously
undermined: cases when a file receives very localised changes when
it gets changed as a part of a project are actually rare.  I mean, the
line of history of a single file ripped from the line of history of a
project that file is a part of might not have much sense, at least
certain commits of it might not have much sense.  Namely, certain
changes might appear in that file as coming out of thin air or
disappearing to nowhere while in fact they were moved in from some other
file and then moved away into some other file, respectively.
I'm still ambivalent on this issue: there are both logical pros and
cons of the ability to copy a file with its full history between
branches.

By the way, [1] contains a good summary of the question being discussed.

1. http://markpasc.livejournal.com/186489.html

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Konstantin Khomoutov
On Tue, 18 Dec 2012 07:47:22 -0800 (PST)
John McKown john.archie.mck...@gmail.com wrote:

 What about something like the following (on Linux)
 
 git checkout -b newbranch
 git ls-files | fgrep -v 'file.to.keep' | while read i;do git rm
 $i;done
 # newbranch now only contains file.to.keep

1) Only provided you then `git add -u` and `git commit` the changes.
2) Only this new commit made in the previous step will only contain
   file.to.keep -- every commit down the line of history will still
   contain all the other files.  Not only this makes the file's history
   impure but merging such a tree to another branch will bring all
   this history with the merge commit.

 git checkout B
 git merge newbranch
 git -d newbranch
 
 I'm not too sure about this. I'm still too new at git to be sure of
 the git ls-files doing what I think.

To do such mass removals of unwanted stuff from *whole* lines of
history, the `git filter-branch` tool was written.  So yes, by applying
`git filter-branch` to a copy of the branch from which we want to
extract the history of a single file, it's possible to achieve what you
intended.  The problem which remains with this approach is tracking
file renames: Git does not track file renames explicitly (like, say,
Subversion does) and each call to the script you pass to
`git filter-branch` will see the state of the branch pulled out of
context.  I'm not sure there's a usable way to somehow find out on
each such step if a file has been renamed or not.

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Dale R. Worley
 From: Konstantin Khomoutov flatw...@users.sourceforge.net
 
 Since Git only records snapshots of whole trees and does not really
 track individual files, there's no such *concept* as the history of an
 individual file -- it might appear to exist (thanks to the
 `git log ... filename` command) but it's implemented as a filter
 applied to the regular line of history plus the trickery named rename
 detection which uses heuristics (controlled by certain knobs).

Personally, I was very fond of svn blame [filename].  It helped me
track down many, many things.

Dale

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Konstantin Khomoutov
On Tue, Dec 18, 2012 at 02:54:54PM -0500, Dale R. Worley wrote:

  Since Git only records snapshots of whole trees and does not really
  track individual files, there's no such *concept* as the history of an
  individual file -- it might appear to exist (thanks to the
  `git log ... filename` command) but it's implemented as a filter
  applied to the regular line of history plus the trickery named rename
  detection which uses heuristics (controlled by certain knobs).
 
 Personally, I was very fond of svn blame [filename].  It helped me
 track down many, many things.

There is `git blame ... file` FWIW.

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-18 Thread Dale R. Worley
 From: Konstantin Khomoutov flatw...@users.sourceforge.net
 
   Since Git only records snapshots of whole trees and does not really
   track individual files, there's no such *concept* as the history of an
   individual file -- it might appear to exist (thanks to the
   `git log ... filename` command) but it's implemented as a filter
   applied to the regular line of history plus the trickery named rename
   detection which uses heuristics (controlled by certain knobs).
  
  Personally, I was very fond of svn blame [filename].  It helped me
  track down many, many things.
 
 There is `git blame ... file` FWIW.

|GIT-BLAME(1)  Git Manual  GIT-BLAME(1)
|
|NAME
|   git-blame - Show what revision and author last modified each line of a
|   file

That's great! ... But the existence of git-blame means that git can,
*in practice*, trace the history of an individual file, and even
individual lines within a file.

Dale

-- 




[git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread lei yang
Hi expert,

now I'm in the branch A, I want to copy some file from branch B to A

any help?

Lei

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread Rick DeNatale
git checkout B -- somefile


On Mon, Dec 17, 2012 at 7:58 AM, lei yang yanglei.f...@gmail.com wrote:

 Hi expert,

 now I'm in the branch A, I want to copy some file from branch B to A

 any help?

 Lei

 --





-- 
Rick DeNatale

Google+: +Rick DeNatale https://plus.google.com/10254117893106790
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread Konstantin Khomoutov
On Mon, 17 Dec 2012 04:58:53 -0800
lei yang yanglei.f...@gmail.com wrote:

 now I'm in the branch A, I want to copy some file from branch B to A
 
 any help?

Note that the already proposed

git checkout $branch -- $filename
git add $filename

approach does not copy the file's history recorded in branch -- you
only get the file's contents.
In general, it's impossible to copy a file from one branch to another,
preserving its history.

Also note that if you want to save the file's contents into a
differently named file, you should use another approach:

git show $branch:$filename  $newfilename

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread lei yang
Thanks for the tips, I have another question, If I forget branch B
files' path, how chould I do without switch to B

Lei

On Mon, Dec 17, 2012 at 6:18 AM, Konstantin Khomoutov
flatw...@users.sourceforge.net wrote:
 On Mon, 17 Dec 2012 04:58:53 -0800
 lei yang yanglei.f...@gmail.com wrote:

 now I'm in the branch A, I want to copy some file from branch B to A

 any help?

 Note that the already proposed

 git checkout $branch -- $filename
 git add $filename

 approach does not copy the file's history recorded in branch -- you
 only get the file's contents.
 In general, it's impossible to copy a file from one branch to another,
 preserving its history.

 Also note that if you want to save the file's contents into a
 differently named file, you should use another approach:

 git show $branch:$filename  $newfilename

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread Thomas Ferris Nicolaisen


On Monday, December 17, 2012 3:22:26 PM UTC+1, lei yang wrote:

 Thanks for the tips, I have another question, If I forget branch B 
 files' path, how chould I do without switch to B 


You can explore the contents of other branches easily in any Git GUI tool. 
Or you can use command line:

git ls-tree B

or if the file was in a subdirectory:

git ls-tree B subdir/ 

-- 




Re: [git-users] Is it possible cp some file from one branch to another without switch branch

2012-12-17 Thread William Mizuta
You can use the option -r in git ls-tree to show all files from a branch:

git ls-tree -r B

With that, you can use a grep to find the file you are searching.


William Seiti Mizuta
@williammizuta
Desenvolvedor da Caelum



On Mon, Dec 17, 2012 at 12:27 PM, Thomas Ferris Nicolaisen tfn...@gmail.com
 wrote:



 On Monday, December 17, 2012 3:22:26 PM UTC+1, lei yang wrote:

 Thanks for the tips, I have another question, If I forget branch B
 files' path, how chould I do without switch to B


 You can explore the contents of other branches easily in any Git GUI tool.
 Or you can use command line:

 git ls-tree B

 or if the file was in a subdirectory:

 git ls-tree B subdir/

 --




--