git - temporary commit on complex merge -
i have 2 branches master
main branch , feature_branch_1
old , many commits behind master. need merge feature_branch_1
master, did:
git pull --rebase origin master
as expected there tons of conflicts, after there need develop feature on new feature_branch_2
, against head
of master , needs worked on before feature_branch_1
. being more or less in middle of complex merge, how do temporary commit on feature_branch_1
can come later. know can a:
git add <things-that-are-done> git commit -m 'intermediary commit between merges' ... come later git checkout 'that-temp-commit-hash' ... after finishing git add . git commit -m 'done feature_branch_1' git rebase --interactive head~1
making temporary commit rebasing squash afterward.
is best way handle this?
git not let make commit index contains unmerged entries.
using git add
resolve away unmerged entries, can commit, approach may unsatisfactory several reasons. without going detail:
- unresolved paths indicated use of index slots 1-3 instead of slot 0. these hold merge-base version of file, , both "sides" (
--ours
,--theirs
, although during rebase roles kind of swapped) of merge. git add
copies work-tree slot 0, clobbering slots 1-3, file resolved (even if work-tree file still full of conflict markers).- an "undo" (
reuc
) entry recorded in index @ point well, cangit checkout -m
path re-create conflict (wiping away slot 0 entry , restoring 1-3 entries). - actually committing merge result loses undo state permanently.
this means if do commit partial merge, , want go , want finish it, information—specifically unmerged state, if moved undo entry—is missing. closest can figuring out, later, files still need merge properly, search conflict markers. (if that's ok you, method may satisfactory after all.)
besides this, rebase copies multiple commits, , have not mentioned whether particular merge conflict has occurred on last such commit. need either finish or abort rebase before going on other operations. (it's technically possible things in middle of rebase, tricky.)
as part:
... come later git checkout 'that-temp-commit-hash' ... after finishing git add . git commit -m 'done feature_branch_1' git rebase --interactive head~1
because particular unmerged-state (which resolved "wrong" on purpose else , come later) result of rebase rather merge, sequence work. simpler, , more applicable, replace last 2 steps git commit --amend
, though. --amend
option tells git commit
make new commit using current commit's parent(s), instead of current commit itself. works both normal (single-parent, non-merge) commits , actual merges (two or more parents).
alternatives
your best bet leave work-tree alone , make 1 handle other issues.
the simplest way that, works every version of git, make clone.
you can make clone cloning in-progress rebase. on sensible systems have hard links, if clone repository repository on same file system, using local paths (git clone work/repo work/new-clone-for-fast-fix
instance, 1 level have been working), git use hard links underlying packs , objects, need work-tree space.
if git relatively new (i recommend @ least git 2.6 although feature there in 2.5), can use git worktree add
create new "linked work-tree". linked work-tree remembers origin repository (and vice versa), has private index / staging-area. can put on whatever branch want , there, including creating other branches or doing other rebases, without disturbing "main" work-tree , "main" index.
Comments
Post a Comment