未跟踪文件的git diff与分支相同的文件显示diff的分支

时间:2018-10-26 16:50:02

标签: git

我有2个文件,file1和file2。
file1在主目录中。
branch1是根据master创建的分支。
file2仅在branch1中。

当我这样做时,我看到一个差异。

$ git checkout branch1
Switched to branch 'branch1'

$ cat file2
branch1 file

$ cp file2 file2_bak

$ git checkout master
Switched to branch 'master'

$ mv file2_bak file2

$ git diff branch1
diff --git a/file2 b/file2
deleted file mode 100644
index 6fbd376..0000000
--- a/file2
+++ /dev/null
@@ -1 +0,0 @@
-branch1 file

为什么在branch1和local中都存在file2时为什么显示差异?有没有办法防止这种差异出现?

1 个答案:

答案 0 :(得分:0)

您的命令git diff branch1branch1与您当前的工作树进行比较。但是git diffs只会跟踪它的内容-对于git,file2中没有master,只有branch1中没有branch1。 diff是从master中的状态到file2中的状态所需的“更改”,这意味着必须删除现有的git diff HEAD branch1。如果您改为使用master,则差异从branch1file2,文件将被添加。但这仅适用于跟踪文件。

您可以简化一件事:无需切换分支即可获得master。在git cat-file blob branch1:file2 > file2 中,您可以

#-------------------------------------------------
#
# Project created by QtCreator 2018-10-25T19:06:04
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = gstreamer_stream_and_display_test
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-1.0 glib-2.0 gobject-2.0 gstreamer-video-1.0

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target