The accepted answer already mentions the use of git checkout . Now in file.py from branch2 may be content that is no longer applicable in branch1 . Such a situation will require the selection of some changes and the abandonment of others. Therefore, to have full control, do an interactive merge using the --patch switch:
$ git checkout --patch branch2 file.py
The interactive mode section of the man page for git-add(1) describes the keys that will be used:
y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk nor any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk nor any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
The split command is especially useful.
pdp Oct. 16 '15 at 10:21 2015-10-16 10:21
source share