Thread (4 messages) flat view 4 messages, 2 authors, 2016-06-15

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

From: Bisani, Alok <hidden>
Date: 2016-06-15 22:46:06

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
==============================================================================
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help