git: diff between file in local repo and origin

后端 未结 7 2123
我在风中等你
我在风中等你 2020-12-04 04:42

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

相关标签:
7条回答
  • 2020-12-04 05:30

    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.

    0 讨论(0)
提交回复
热议问题