Is there some kind of 'git rebase --dry-run', which would notify me of conflicts in advance?

后端 未结 5 2146
野的像风
野的像风 2020-12-13 23:54

I\'m trying to script rebasing and my script will take different paths depending on if the rebase results in any conflicts.

Is there a way to determine if a rebase w

5条回答
  •  既然无缘
    2020-12-14 00:11

    You still can do git rebase, play with it as you want, than recover all the changes from before. Assuming you have done your rebase of some branch into the master, and you don't like it:

    1. git reflog -20 - gives you last 20 positions of your HEAD with a little description
    2. git checkout - places your HEAD on the branch
    3. git reset --hard - places your HEAD and branch on the old ref, this way you can recover old branch.

    There are some mechanics to understand here:

    1. You NEVER delete anything in git, not with commands, anyway. Its the garbage collector that comes through and deletes unreferenced branches (default 3 months). So your branch, from before the rebase, still exists.
    2. Same goes for the on same branch rebase, its just a new tree rewritten next to the old one.
    3. All the history of rebase and your other on HEAD manipulations is written in the reflog
    4. You can use @{N} annotations from reflog

    So, nothing is lost after the rebase, you just have to know how to find and recover it.

    For example you can place yourself a tag before the rebase than revert to it or delete it. it evades you all the SHA1 research step.

提交回复
热议问题