I need to revert a commit but only if there will not be conflicts. Something like git revert --only-if-no-conflicts
but there isn't such option and there is no --dry-run
(--no-commit
will still affect working copy which I need to avoid).
In this case, the revert is run from a script so I cannot manually inspect whether there have been conflicts or not. I can do that somehow from the script but before diving into that, isn't there some clever way to make Git do the revert only if it will succeed without conflicts?
The script should:
Branch, revert, observe.
If you don't want to touch your working tree, you can create a new directory with git-new-workdir
, for example in /tmp
.
Then you could plainly,
new branch $ git revert --no-edit ce6982e || \
{ export REVERT_FAILED=yes; git revert --abort; }
Go back to the original branch and act on the observation, ie revert if the revert on the staging branch was successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With