I have some confussion with git, so I created a toy sample which would let me understand how to solve my problem. Let's say I have a repo in which one of the files requirements.txt
look like this:
# requirements.txt
A
B
C
D
Let say I added in a new branch two lines of code:
git checkout -b newbranch
git add .
git commit -m "B2 B3"
git checkout master
git merge newbranch
# requirements.txt
A
B
B2
B3
C
D
But then the collaborative history continues in master, and someone else creates new content, adding, updating or deleting other files and so on. After pulling master from the remote repo, the requirements file on my master looks like this (my previous changes were deleted by new commits, and also C ):
# requirements.txt
A
B
C1
C2
D
E
Now I want to restore the lines B1 and B2 which were added in newbranch
, but without deleting what others did on master. Namely, my desired output would be:
Whatever GitMagicCommands to do this??:
# requirements.txt:
A
B
B2
B3
C1
C2
D
E
Which Git commands could I use to accomplish that in the best way (I assume there could be conflicts)?