I want to find the differences between a file I have in my local repo vs what is in the origin master
.
I know that there is git diff
, howev
For that I wrote a bash script:
#set -x
branchname=`git branch | grep -F '*' | awk '{print $2}'`
echo $branchname
git fetch origin ${branchname}
for file in `git status | awk '{if ($1 == "modified:") print $2;}'`
do
echo "PLEASE CHECK OUT GIT DIFF FOR "$file
git difftool FETCH_HEAD $file ;
done
In the above script, I fetch the remote main branch (not necessary its master branch ANY branch) to FETCH_HEAD
, then make a list of my modified file only and compare modified files to git difftool
.
There are many difftool
supported by git, I configured Meld Diff Viewer
for good GUI comparison.
From the above script, I have prior knowledge what changes done by other teams in same file, before I follow git stages untrack-->staged-->commit
which help me to avoid unnecessary resolve merge conflict with remote team or make new local branch and compare and merge on the main branch.