git - Re-merging after "Selective" or "Partial" Merge -
here's reproducible example of problem i've gotten myself into:
setup
mkdir test-git cd test-git git init echo 'hello, world.' > file1.txt git add . git commit -m 'init commit' git branch branch2 git checkout branch2 echo 'hello, universe' > file1.txt echo 'foobar' > file2.txt git add . git commit -m 'commit 2'
i wanted merge branch2 master changes file1.txt
, here's did:
git checkout master git merge branch2 --no-commit --no-ff git reset -- file2.txt git commit -m 'partially merged branch2 master!'
so here's realized might not have been idea... let's changed mind , want merge file2.txt in well. can run:
git merge branch2
response: up-to-date.
if run git diff branch2 --name-status
returns d file2.txt
, guess when unstaged file2.txt tracked deletion? still don'y understand why can't merge on , wouldn't add file (i don't understand git's merge algorithm well).
unfortunately, scenario more complicated can't reverse commit. there easy way remerge differences between master
, branch2
, without rewriting history?
in git merge commit supposed have necessary changes parents. if committer deliberately decided pick version of file did, resulting commit considered "a right merge" , it's impossible perform "further merge".
this behavior has reasons. suppose 1 makes additional change file2.txt
in branch2
after 1st merge commit, , perform merge of branch2
master
(a quite typical situation, isn't it?). should considered correct state of file2.txt
. expect second merge should contain changes made between 2 merges, right? desire other behavior, when git collects changes file2.txt
unapplied far since beginning of history. quite annoying.
nevertheless can "alternative merge". is, jump commit before merge on master
branch (in example, 'init commit') , issue git merge
once again.
if history rewriting isn't appropriate needs, might create new branch b3
@ commit, perform merge, , merge b3
master. definitely, receive merge conflict on file2.txt
, should resolve providing "proper variant" it.
Comments
Post a Comment