How to Diff between local uncommitted changes and origin

后端 未结 4 1380
我在风中等你
我在风中等你 2021-01-29 20:49

Let\'s say I cloned a repository and started modifying files. I know that if I have local uncommitted changes, I can do a diff as follows git diff test.txt and it w

相关标签:
4条回答
  • 2021-01-29 20:55

    Given that the remote repository has been cached via git fetch it should be possible to compare against these commits. Try the following:

    $ git fetch origin
    $ git diff origin/master
    
    0 讨论(0)
  • 2021-01-29 20:56

    If you want to compare files visually you can use:

    git difftool
    

    It will start your diff app automatically for each changed file.

    PS: If you did not set a diff app, you can do it like in the example below(I use Winmerge):

    git config --global merge.tool winmerge
    git config --replace --global mergetool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
    git config --global mergetool.prompt false
    
    0 讨论(0)
  • 2021-01-29 20:57

    I know it's not an answer to the exact question asked, but I found this question looking to diff a file in a branch and a local uncommitted file and I figured I would share

    Syntax:

    git diff <commit-ish>:./ -- <path>
    

    Examples:

    git diff origin/master:./ -- README.md
    git diff HEAD^:./ -- README.md
    git diff stash@{0}:./ -- README.md
    git diff 1A2B3C4D:./ -- README.md
    

    (Thanks Eric Boehs for a way to not have to type the filename twice)

    0 讨论(0)
  • 2021-01-29 21:09

    To see non-staged (non-added) changes to existing files

    git diff

    Note that this does not track new files. To see staged, non-commited changes

    git diff --cached

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