How to merge specific files from Git branches

后端 未结 11 1871
长发绾君心
长发绾君心 2020-11-30 16:23

I have 2 git branches branch1 and branch2 and I want to merge file.py in branch2 into file.py in branch1 and only that file.

In essence I just want to work on the fi

11条回答
  •  生来不讨喜
    2020-11-30 16:49

    Although not a merge per se, sometimes the entire contents of another file on another branch are needed. Jason Rudolph's blog post provides a simple way to copy files from one branch to another. Apply the technique as follows:

    $ git checkout branch1 # ensure in branch1 is checked out and active
    $ git checkout branch2 file.py
    

    Now file.py is now in branch1.

提交回复
热议问题