0

I want to revert a commit that contains added binary (LFS) files. As they are binary, they cannot be merged. I invoke the revert command as

git revert cd68ab2f306c8db28d6887ece8e1e754e6b3b0d1 --strategy=ort --strategy-option=theirs

Unfortunately, this prints "CONFLICT (modify/delete) [...] File deleted in parent [...] and modified in HEAD" and leaves the index in a conflicting state. This is unexpected, as I've told git revert to always take "theirs", so it should delete the added file in the working directory.

The command is invoked from a script, so manually git rm the files is not a nice option for me.

Sc4v
  • 348
  • 2
  • 10
  • Even if `--strategy=theirs` did what you want, it is dangerous, because conflicts could arise outside of LFS-managed files. Then those conflicts would not be resolved, but ignored and overwritten with "their" version. – j6t Aug 23 '22 at 10:54
  • 1
    The `-X ours` and `-X theirs` eXtended-strategy-options (as I call them to make them clearly different from the `-s` option for selecting a strategy) only apply to conflicts *within a single file*, never to a high level or tree-level conflict like the one here (modify/delete). That's just a Git rule: the `-X` options are passed on to the low-level merge step, and not interpreted by the high-level merge step. – torek Aug 23 '22 at 21:25
  • The only way to automate this after the fact is to write some tooling that uses the `git ls-files --stage` operation to read the index. – torek Aug 23 '22 at 21:25

1 Answers1

0

When reverting a commit, git first diffs the commit to the parent commit (if it is not a merge commit). Then tries to create a commit on top of the HEAD which reverses what that commit does. When the diff contains a binary file, and the binary file changed at least once after that commit, than git can not know how to undo that file even with the --strategy=ort --strategy-option=theirs. Git asks your help on how to resolve this conflict. So, you can resolve the conflict with git rm <the-binary-file> and git revert --continue.

The second way is, since all git revert will do is to create a commit that will remove that file, you can do it yourself without revert like:

git rm <the-binary-file>
git commit -m 'Revert adding the file'