How to renegotiate and merge "stateful" in Git?

I may be thinking too much about this, but can anyone clarify the following statement?

Counter-intuitively, renegotiations and merges are kept in state, and git may give way back to you before the merge / redirect is complete.

After a quick overview of state , I believe it has to do with permutations and merges, consisting of sequential (sequential) steps, where each step is an atomic change and therefore can be rolled back. It's right? Can anyone explain this better and why is it inconsistent? If rebase and merge weren't restrained, would they be irreversible?

Finally, reinstall and merge state only in Git?

+3


source to share


3 answers


As the original bad explainer commentator , I can clarify what I meant there.

Unlike many git commands (like checkout) that update your repo / index / workdir and then return control to you, it's possible for git to exit the middle of a merge or rebase and return control to the user. This is especially important because it gives you the opportunity to resolve merge conflicts before continuing with the merge or reload.

git merge --abort
git rebase --continue | --skip | --abort | --edit-todo

      

If the merge fails, git will show you this message:

Automatic merge error; fix conflicts and then commit the result.



And during the rebase , git will show you this message:

Failed to merge changes.

Patch failed (step)

When you have solved this problem, run "git rebase -continue". If you'd rather skip this patch, run "git rebase -skip" instead. To rebase the original branch and stop restarting "git rebase --abort".

In any case, the launch git status

will list some files as

# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#   both modified:      YOURFILE
#

      

This is not particularly contrary to expectations, unless you expect git to either succeed completely or fail immediately before returning control to you. You may also run into problems if you leave a directory in the middle of a merge or reinstall, forget about it and come back to it later expecting it to work as usual. One useful technique is to add your branch name and merge state to the shell prompt , which I have found useful for remembering what state my working directory is in at any given time.

+2


source


This means that git stores state information inside the .git directory, which it uses to keep track of what it is doing.

To see it for the merge type git merge --no-commit <some branch>

, then ls -l .git

, and you will see the files MERGE_HEAD, MERGE_MODE and MERGE_MSG. When a merge occurs, these files are removed.



For rebase, just do something like git rebase -i HEAD~1

and change any line from "pick" to "edit". When git returns control to you ls -l .git

, you will see that there is a .git / rebase-merge directory created with a whole bunch of files, including a list of recovery actions that still need to be done. git rebase --abort

(or when the summary ends on its own) and these files are deleted.

I have no idea why a person who said he thought any of these operations had a condition is counterintuitive. If you are chunking commits one by one via rebase, you should have a "todo" list stored somewhere. And if you are merging, you have to know what is merged in SHA, so you do on it in addition to HEAD.

+4


source


Quite simply, once you start a merge or rebase, it is "in progress". It's not finished yet and you need to either fold it back or fix it. You cannot execute other basic git commands (commits for example).

+1


source







All Articles