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 repositoryAs stated, use gitk --all, then in View | New view, enable All Branches. Then set your search criteria: filenames (with wild cards) in the penultimate field. Finally: OK.
The git diff command is used to perform the diff function on Git data sources. For example, commits, branches, files, and so on. It can also be used to compare two files of different branches.
In order to compare two branches easily, you have to use the “git diff” command and provide the branch names separated by dots. Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications.
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
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 )
}
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