8

I am trying to script some git operations which involves some rebasing/cherry-picking/etc.

Is there a way to resolve a conflict without having to run commands such as:

git rebase --continue
git cherry-pick --continue
git merge --continue

I am trying to avoid the editor ever being executed when git wants a commit message.

Perhaps there is a way to tell git that things have been resolved and pass in a default commit message if needed?

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • There are lots of ways to provide a commit message noninteractively (`-m`, `-C`, `-F`, just to name a few from `git commit`). None of them are specific to conflict resolution. – chepner Apr 14 '15 at 15:18
  • Is there a way to tell git that all conflicts are resolved without having to use *--continue? – Jonathan.Brink Apr 14 '15 at 15:59
  • I'm not sure I understand. By definition, a conflict is something that requires manual intervention, and `git` has no way of knowing that the manual intervention is over without you running *something* like `git whatever --continue`. – chepner Apr 14 '15 at 16:00
  • Let me try to explain a little more, I'm writing a script that is like a wrapper on top of git and gerrit. At various times in my script I am rebasing, cherry-picking, and stashpopping. When I invoke those actions and a conflict arises, I want the user to be in a generic conflict mode. The user manually updates the files under conflict and then just pushes a "done" button. But I've seen (for example with cherry-pick --continue) git wants a commit message so it brings up the editor which is what I want to avoid. – Jonathan.Brink Apr 14 '15 at 16:22
  • The -x option for cherry-pick is nice, but I want to insert my own custom commit message, and I want to be able to do this generically...not just in the cherry-pick situation – Jonathan.Brink Apr 14 '15 at 16:22
  • Your script can just record which action it is about to take (`action=rebase; git rebase ...`), and if a conflict occurs, use `action` to continue afterwords (`git $action --continue`). – chepner Apr 14 '15 at 16:24
  • That doesn't guard against git trying to bring up an editor for the commit message... – Jonathan.Brink Apr 14 '15 at 16:28
  • Like I said earlier, most commands provide options for specifying a commit message. The editor is only pulled up in the absence of one of those options. – chepner Apr 14 '15 at 16:28
  • there must be a plumbing command to simply tell git "everything is resolved" rather than having to script around the problem – Jonathan.Brink Apr 14 '15 at 16:30
  • Ok, I read several documentation(http://think-like-a-git.net/) and can tell that there is no command like this one you want. It's because revision tree is not similar after founding conflict within rebasing on cherry picking, because of different side afects and so on. You proppably should save somewhere which one command was started and than with several keys like '-m' or '-x' call the needed one. – Roman Makhlin Apr 17 '15 at 13:09
  • Ok, thanks for looking through the documentation. I guess there just doesn't exist this general purpose plumbing command I'm looking for. If you expand this into an answer I'll mark it....Or you could update your answer below and I'll mark it correct... – Jonathan.Brink Apr 17 '15 at 13:54
  • Why use the term "plumbing" in the title of your question? `commit`, `rebase`, and `cherry-pick` are *porcelain*, not *plumbing*, commands. – jub0bs Apr 20 '15 at 15:33
  • I use the term plumbing because I want a _plumbing_ command to quit the rebase/cherrypick etc. A plumbing command that is an alternative to "* --continue" – Jonathan.Brink Apr 20 '15 at 17:54
  • @Jonathan.Brink I don't think you understand the [porcelain/plumbing terminology](http://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain)... – jub0bs Apr 21 '15 at 10:34

2 Answers2

5

You can use git commit -m '$msg' to commit the changes, then issue a command saying "keep going with the next steps" :

For git rebase :

git commit -m '$msg'
git rebase --skip

For git cherry_pick :

git commit -m '$msg'
# if you are cherry-picking several commits at once,
# this will skip the current (conflicting) one, and proceed with the remaining ones :
git reset
git cherry-pick --continue

For git merge :
There is no git merge --continue directive. In case of conflict you just fix the conflict, then commit. So git commit -m '$msg' will do it.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Yes, git rebase --skip _after_ creating a commit to fix the conflicts seems to work! As well as just doing the commit after a cherry-pick. So, turns out I didn't really need a plumbing command...I just needed to create the commit manually rather than having git finish the job. – Jonathan.Brink Apr 20 '15 at 18:03
3

Try to use -x option. Thats options does:

-x When recording the commit, append a line that says "(cherry picked from commit ...)" to the original commit message in order to indicate which commit this change was cherry-picked from. This is done only for cherry picks without conflicts. Do not use this option if you are cherry-picking from your private branch because the information is useless to the recipient. If on the other hand you are cherry-picking between two publicly visible branches (e.g. backporting a fix to a maintenance branch for an older release from a development branch), adding this information can be useful.

git-scm.herokuapp.com/docs/git-cherry-pick

Also --allow-empty may be usefull

Roman Makhlin
  • 973
  • 1
  • 11
  • 27
  • Thanks for this, but I'm looking for a more general solution to when conflicts occur. This applies for rebase, cherry-pick, merge, stashpop, and I'm sure others – Jonathan.Brink Apr 12 '15 at 16:03
  • Could You please provide some details of which behaviour did you want to implement? For example: if on cherry-pick there is some merge conflicts how do You suppose to solve it: just say nothing to console and keep going(which way propably can not exists) or maybe You wish return back all your changes(http://stackoverflow.com/questions/2073841/how-can-i-discard-remote-changes-and-mark-a-file-as-resolved) and so on. – Roman Makhlin Apr 14 '15 at 12:06
  • When the conflict arises, the user fixes the conflicts and then just pushes "the done button". No additional input (for example, entering a commit message). – Jonathan.Brink Apr 14 '15 at 12:12
  • You can use 'git mergetool -t' (https://git-scm.herokuapp.com/docs/git-mergetool) and then your script. If script returns '0' then - git decides that conflict is solved. – Roman Makhlin Apr 14 '15 at 12:16
  • But it still brings up the editor at times which is what I'm really trying to avoid. For example, when using the "git cherry-pick --continue" command, it brings up the editor asking for a commit message. – Jonathan.Brink Apr 14 '15 at 12:27
  • How to try combine it with my previous answer, a key '-x' – Roman Makhlin Apr 14 '15 at 12:36
  • Yes, that's very close (and I should have been more clear...sorry) but as stated in the original question, I don't want to have to run a specific "--continue" command as that requires me knowing if the conflict started as a rebase, cherry-pick, stashpop, etc... – Jonathan.Brink Apr 14 '15 at 12:44