Search code examples
gitgit-rebasegit-merge-conflict

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


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 would result in conflicts before executing the rebase?


Solution

  • At the time of writing this (Git v2.6.1 v2.10.0), the git rebase command offers no --dry-run option. There is no way of knowing, before actually attempting a rebase, whether or not you're going to run into conflicts.

    However, if you run git rebase and hit a conflict, the process will stop and exit with a nonzero status. What you could do is check the exit status of the rebase operation, and, if it is nonzero, run git rebase --abort to cancel the rebase:

    git rebase ... || git rebase --abort
    

    And if the rebase is successful but you realise that you want to undo it, you can run

    git reset --hard @{1}