'git diff'没有给出任何输出 [英] 'git diff' doesn't give any output
问题描述
如果运行git diff
,我希望看到工作目录相对于之前已提交的内容的更改列表(或工作目录内容的列表,如果它是没有提交的新存储库).试试这个例子:
If I run git diff
I would expect to see a list of changes of my working directory relative to whatever had been committed before (or a list of the working directory contents if it's a new repository with no commits). Try this example:
$ mkdir temp
$ cd temp
$ git init
$ echo "first line" > test.txt
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# test.txt
nothing added to commit but untracked files present (use "git add" to track)
让我们看一下test.txt的不同之处:
Let's see a diff of test.txt:
$ git diff
这没有任何输出!
我希望看到像+ first line
这样的差异,但我什么也没得到.它没有告诉我发生了什么事. Stack Overflow上的人告诉我git add
一些文件,所以我这样做:
I would expect to see a diff like + first line
, but instead I get nothing. It doesn't tell me what's going on. People on Stack Overflow tell me to git add
some files so I do:
$ git add .
$ git diff
什么都没有!
Git GUI 显示所做的更改.
git status -v
显示更改.
但是由于某些原因,git diff
没有显示任何内容.
But for some reason git diff
doesn't show anything.
所以我的问题是:
-
git diff
是如何工作的? - 如何显示我所做的所有更改(未暂存和暂存)的差异?
- How, in plain English, does
git diff
work? - How can I show a diff of all the changes I've made (unstaged and staged)?
我公司的某些人正在使用Git,但是SVN人群会指出这一点,因为Git太混乱而无法使用.
Some people at my company are using Git, but the SVN crowd are going to point at this as a case of where Git is too confusing to be usable.
推荐答案
为什么在添加前没有得到git diff
输出?
Git不会将文件系统中的文件视为版本控制系统中自动包含的文件.您必须将内容显式添加到Git存储库中(就像通过使用git add .
添加当前目录来进行操作一样).
Why do you get no git diff
output before adding?
Git does not treat files in the filesystem as automatically included in the version control system. You have to add things explicitly into the Git repository (as you are doing by adding the current directory with git add .
).
没有输出到git diff
,因为Git在存储库的内部中看不到任何更改,仅在存储库的外部中看到文件,该文件被视为未跟踪",并且因此在生成差异时忽略.
There is no output to git diff
because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.
我发现这是与版本控制系统(如SVN(以及暂存和忽略目录))的主要区别之一.
I found this one of the key differences to version control systems like SVN (along with staging and ignoring directories).
如果要包含未跟踪的文件,请git add
它们.
If you want the untracked files to be included, git add
them.
如果您不希望它们出现在存储库中,请将它们添加到您的.gitignore
中(请参阅git ignore --help
).这对C对象文件或Python .pyc
文件很有用.
If you don't want them in your repository, add them to your .gitignore
(see git ignore --help
). This is good for C object files or Python .pyc
files.
所以这有点不同.如果执行git status
,您将看到文件现在位于暂存区域中.这是您要提交的文件的区域.
So this is slightly different. If you do git status
you will see the file is now in the staging area. This is the area for files that you are about to commit.
当您将新文件git add
放入Git存储库时,它会跳过工作副本并直接进入暂存区域.从某种意义上说,这是有道理的,并且git add
始终将文件移动到暂存区中,无论是已跟踪还是未跟踪.
When you git add
a new file into the Git repository, it skips the working copy and goes straight into the staging area. This make sense in a way, and git add
always moves files into staging area whether it is tracked or untracked.
要查看最后一次签入和登台区域之间的差异,请执行git diff --cached
.
To see the differences between the last check in and the staging area do git diff --cached
.
要查看临时区域和工作副本之间的差异,请执行git diff
.如果暂存区中没有任何内容,则与在上次签入和工作副本之间进行区别相同.
To see the differences between the staging area and your working copy, do git diff
. If there is nothing in the staging area then this is the same as doing a diff between the last check in and your working copy.
这篇关于'git diff'没有给出任何输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!