diff current working copy of a file with another branch's committed copy

后端 未结 6 2110
醉话见心
醉话见心 2020-12-12 13:27

I have a repo with file foo in the master branch. I switched to bar branch and made some changes to foo. How can I now run a git diff

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 13:41

    You're trying to compare your working tree with a particular branch name, so you want this:

    git diff master -- foo
    

    Which is from this form of git-diff (see the git-diff manpage)

       git diff [--options]  [--] [...]
           This form is to view the changes you have in your working tree
           relative to the named . You can use HEAD to compare it with
           the latest commit, or a branch name to compare with the tip of a
           different branch.
    

    FYI, there is also a --cached (aka --staged) option for viewing the diff of what you've staged, rather than everything in your working tree:

       git diff [--options] --cached [] [--] [...]
           This form is to view the changes you staged for the next commit
           relative to the named .
           ...
           --staged is a synonym of --cached.
    

提交回复
热议问题