1

I'm looking for a way I can automatically add all new files, but not mark conflicts as resolved.

I have set up some ant scripts to do basic Git functions to help non-developers handle routine operations. Been doing this for a while and decided that it would be safe to have the "commit" script automatically add new files. Easy, just have the script do git add --all before the commit.

Except that that has the unintended side effect of marking any conflicts as resolved, which I absolutely do not want to do. Conflicts should stay unresolved so the user knows something is wrong and will ask me how to handle it.

Surprisingly, there doesn't seem to be an option to make git add not mark resolved conflicts. I am about to do some experimenting to see what the scripts need to look for to determine that a conflict resolution is in progress and check that. But thought I would ask folks if there is an easier way to do this.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
kencorbin
  • 1,958
  • 1
  • 20
  • 18

2 Answers2

1

Conflicts can occur two ways: during a merge, and during a rebase. It should be safe to assume that if either of those are in progress, we don't want to auto-commit anything.

The solution, in the form of a script:

#!/bin/bash
git merge HEAD &> /dev/null
result=$?
if [ $result -ne 0 ]
then
  echo "Merge in progress."
  echo "Please resolve any conflicts and complete the merge!"
elif [ -d .git/rebase-merge -o -d .git/rebase-apply ]
then
  echo "Rebase in progress."
  echo "Please resolve any conflicts and complete the rebase!"
else
  # Original commit script goes here. E.g.:
  git add --all
  git commit -m "auto commit"
fi

(Pulled together from How to determine if Git merge is in process and How to know if there is a Git rebase in progress.)


I'd also like to encourage you to consider making this a temporary solution. With a small amount of training, even non-developers should be able to handle most routine Git operations, especially with a GUI front end such as SourceTree.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
0

Conflicts come only when you pull something from server - like doing a rebase or a merge - how come rebase or merge could have continued w/o fixing the conflicts? The best place to take care for this issue is while you rebase or merge something in your local branch.

prabodhprakash
  • 3,825
  • 24
  • 48