git merge: Removing files I want to keep!

前端 未结 5 1363
别跟我提以往
别跟我提以往 2020-11-28 05:08

How can you merge two branches in git, retaining necessary files from a branch?

When merging two branches, if a file was deleted in one branch and not in an

5条回答
  •  清酒与你
    2020-11-28 05:45

    Casey's example didn't work for my case - I couldn't checkout test.txt from master, because it was no longer in that branch:

    $ git checkout master test.txt
    error: pathspec 'test.txt' did not match any file(s) known to git.
    

    Happily I could pull the file out of branchA's own HEAD:

    $ git checkout branchA
    $ git merge --no-commit master
    $ git checkout HEAD test.txt
    $ git add test.txt
    $ git commit
    

提交回复
热议问题