Git diff与远程分支没有显示预期的差异

时间:2018-02-13 22:04:29

标签: git

关注compare local git branch with remote branch?,我试图显示与远程分支的区别,但它似乎没有按预期工作。这是我的git status

Kurts-MacBook-Pro:dashboard kurtpeek$ git status
On branch session-deletion
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   urls.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../../.env
    templates/sessions/_delete.html

no changes added to commit (use "git add" and/or "git commit -a")

我的git branch --all包含remotes/origin/staging

Kurts-MacBook-Pro:dashboard kurtpeek$ git branch --all | grep remotes/origin/staging
  remotes/origin/staging

git diff urls.py显示了我确定与staging分支同时存在的差异:

Kurts-MacBook-Pro:dashboard kurtpeek$ git diff urls.py
diff --git a/lucy-web/dashboard/urls.py b/lucy-web/dashboard/urls.py
index bcbb6af2..15d75b84 100644
--- a/lucy-web/dashboard/urls.py
+++ b/lucy-web/dashboard/urls.py
@@ -204,6 +204,11 @@ urlpatterns = [
         views.SessionUpdate.as_view(),
         name='session'
     ),
+    url(
+        r'^sessions/(?P<pk>[0-9]+)/delete$',
+        views.SessionDelete.as_view(),
+        name='session-delete'
+    ),
     url(
         r'^sessions/(?P<pk>[0-9]+)/schedule/(?P<target>[a-z]+)$',
         views.SessionSchedule.as_view(),

我尝试过对git diff的各种调用,将远程staging分支与我的本地session-deletion分支进行比较,但没有一个显示出任何差异:

Kurts-MacBook-Pro:dashboard kurtpeek$ git diff session-deletion remotes/origin/staging -- urls.py
Kurts-MacBook-Pro:dashboard kurtpeek$ git diff remotes/origin/staging.. -- urls.py
Kurts-MacBook-Pro:dashboard kurtpeek$ git diff remotes/origin/staging... -- urls.py
deletion..remotes/origin/staging -- urls.py
Kurts-MacBook-Pro:dashboard kurtpeek$ 

知道这里的问题是什么吗?

1 个答案:

答案 0 :(得分:2)

使用diff $ref..隐含$ref..HEAD,因此它不会比较工作目录的本地状态,而是比较两个“真实”引用。

要将ref与工作目录中的内容进行比较,请使用diff $ref

手册页摘录:

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

   git diff [--options] <commit> <commit> [--] [<path>...]
       This is to view the changes between two arbitrary <commit>.

   git diff [--options] <commit>..<commit> [--] [<path>...]
       This is synonymous to the previous form. If <commit> on one side is omitted,
       it will have the same effect as using HEAD instead.