git checkout effect on ls-files --others, how to merge partially?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

	I found a feature that was a bit surprising. Basically, a file
exist on master as untracked (git-ls-files --others). It is git-add'ed
on a branch. Now switching back to master, removes the file from
master's working directory as well.

	Whereas, I was expecting it to simply be present as an untracked
file on master as before. This maybe be unreasonable expectation, but
still. To bring the file back on the master branch I had to $ git merge
<branch>. This, however, would pull in all the changes from the branch.
Whereas, I want to limit the merge only to the file.

	Is there a way to pull in changes from a branch but only limited
to a file/files? I ended up doing a manual restore using git-cat-file
<branch>@{0}:/file. And checked in.

    $ git init

    $ echo first > first

    $ echo second > second

    $ git add second

    $ git commit

    $ git ls-files
    first

    $ git ls-files --all

    $ git ls-files --others
    second

    $ git ls-files --others --cached
    first
    second

    $ git checkout -b test_branch HEAD

    $ git branch
      master
    * test_branch

    $ git ls-files --cached
    second

    $ git ls-files --others
    first

    $ git add first

    $ git commit -m "first"

    $ git ls-files --cached
    first
    second

    $ git ls-files --others

    $ git checkout master

    $ git ls-files --others
    # the file "first" which was --others before, has now been removed
upon checking out master

    $ git cat-file blob test_branch@{0}:first > first
    # To bring the file first back on the master branch as an untracked
file

Best regards,
Alok

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux