On Wed, Jul 07, 2021 at 02:36:51PM -0700, 'Chris Ryan' via Git for human beings 
wrote:

> Hello. New member with first post here. For about a 2 years I've been using 
> a one-person git system (on Bitbucket). Nothing fancy. Mainly to maintain 
> an audit trail of changes to about half a dozen text files, and to make 
> sure I could always get the most current version when working at disparate 
> computers in different offices, on two different operating systems (Windows 
> 10 and Linux Mint).
> 
> 
> I am now in an awkward situation that may best be described 
> diagrammatically, below. Is there any good, git-centric way to get my 
> colleague's added lines (colleague's "file Q") into my main document 
> (called "file A" in master; called "file Z" in withindex)
> 
> Thank you.
> 
> master contains several files
> |  all in directory D1
> |
> |
> |----------------------------------|
> |                                  |
> V                                  V
> a series of edits                 gave copy of file A, but 
> and commits involving             named as "file Q", 
> file A in D1. Pushed.             to non-git-using                |        
>                          colleague
> |                                 who added a number
> |                                 of lines, changed nothing else
> |                                 and sent it back to me
> |                                 I want those lines to be in    |          
>                        file A
> |
> |---------------|
> |               |
> |               |
> |               V
> |               new branch called "withindex"
> |               created new subdirectory "D1A"
> V               git mv all project files into it.
>                 A few deletions from file A.
>                 Renamed file A to "file Z"
>                 Committed, not pushed.

Yes.
A command

  $ git show "withindex:D1A/file Z"

(the double quotes are only there to prevent the shell from interpreting the
space in the file name) should dump to stdout ("to the console") the contents
of the "file Z" located under the directory "D1A" as recorded in the tip
commit of the branch named "withindex".
You can easily use shell redirections to save this contents to any file you
wish on a filesystem.

So, the full sequence I'd do would be like this:

1. Check out "master":

  $ git checkout master

2. Overwrite the contents of "file A" under "D1" with the contents of "file Z"
   located under "D1A" as recorded in the tip commit of the branch "withindex":

   $ git show "withindex:D1A/file Z" > "D1/file A"

   (Note that that '>' character is a shell redirection mentioned above: it
   tells the shell to connect the so-called standard output stream of the
   process executing `git show ...` to the file on the right side of '>';
   the file will be created if needed or truncated if it exists.)

3. Run `git diff` to verify the changes in "D1/file A" are expected.

   If they are not, zap them by running

   $ git checkout -- "D1/file A"

   and get back to us.

4. If all is well, `git add` the change, then commit.

   You can then get rid of the "withindex" branch.


Please note that when specifying the name of the file in a `git show` command,
you should use Unix-y forward slashes, '/', always, on any platform, but if
you intend to run these commands in a standard shell on Windows, you should
use '\' as a path separator when setting up the shell redirection explained on
step 2. But if you're using Git Bash on Windows, then again, use '/' when
setting up a shell redirection.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/20210708075639.fvhysd5cr4wv3aak%40carbon.

Reply via email to