Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to dry-run a `git revert`?

Tags:

git

git-revert

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?

like image 879
Borek Bernard Avatar asked Oct 20 '22 14:10

Borek Bernard


1 Answers

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.

like image 126
mockinterface Avatar answered Oct 27 '22 21:10

mockinterface