Reputation: 2406
I would like to search git branches for any modified files in common between mine and all others, as a method of early conflict detection. Is there a method that git would allow me to do this that I'm overlooking (or via shell scripting)?
The method I've thought of for now is, as a post-commit hook:
git diff --name-only master
on the branch I'm in, to determine all the files I'll be searching for in other branches (to generate a list of conflicting branches)git diff --name-only origin/<remote branch> origin/master
on the remote repositoryUpvotes: 8
Views: 261
Reputation: 60275
potentially-conflicting-changes-between () {
local base=`git merge-base $1 $2`
{ git diff --name-only $base $1
git diff --name-only $base $2
} | sort | uniq -d
}
will show all files that merge would examine for conflicts, then it's just a matter of running the refs, easiest might be
for other in `git branch -r`; do
printf '--- \n%s %s\n' master $other
potentially-conflicting-changes-between master $other
done
You can also do the low-level merge prep directly to eliminate false positives on identical changes, this could save much time but will list index details for all potential conflicts and checks whether the merge could actually run in your current worktree without stomping on uncommitted work
potentially-conflicting-changes-between ()
{
( export GIT_INDEX_FILE=`git rev-parse --git-dir`/scratch-index;
git read-tree --empty;
git read-tree -m $(git merge-base $1 $2) $1 $2;
git ls-files -u )
}
Upvotes: 3
Reputation: 1324258
Most of the available methods are listed in "How can I preview a merge in git?"
The second step you mention is one of the fastest (compared to actually perform the merge with --no-ff
and --no-commit
)
git diff --name-status origin/abranch
(compared to HEAD by default)
You can add a status filter, since you search for modified files (common files between branches with modification)
No need for the first step: the second one will directly list common modified files compared to HEAD.
git diff --name-status --diff-filter=M origin/abranch
Upvotes: 4