git diff不提供输出 [英] git diff gives no output

查看:159
本文介绍了git diff不提供输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行 git diff ,我希望看到我的工作目录相对于之前提交的任何更改的列表(或工作目录内容的列表如果这是一个没有提交的新回购)。试试这个例子:

  $ mkdir temp 
$ cd temp
$ git init
$回声第一行> test.txt
$ git status
#分支大师
#未追踪文件:
#(使用git add< file> ...来包含提交)

#test.txt
没有添加提交,但未跟踪的文件存在(使用git add跟踪)

让我们看一下test.txt的差异:

  $ git diff 

这不会产生输出结果!

我期望看到像 +第一行之类的差异,但是我什么也得不到。它并没有告诉我发生了什么事。在stackoverflow上的人告诉我 git add 一些文件,所以我这样做:

  $ git add。 
$ git diff

还没有!



Git GUI 显示更改。

git status -v 显示更改。



但由于某些原因 git diff 不会显示任何内容。

所以我的问题是:


  1. 用简单的英语, git diff work?

  2. 如何显示我所做的所有更改(非暂存和暂存)的差异?

我公司的一些人正在使用git,但是SVN人群会指出这是git太混乱而无法使用的情况。


<为什么在添加之前没有获得git diff?

git不会将文件系统上的文件视为自动包含在版本控制系统中,你必须明确地将东西添加到git仓库中(就像通过添加当前目录 git add。)一样。



没有输出到 git diff ,因为git在你的版本库里面看到没有改变,只有文件在外部存档ry,它认为'未跟踪',因此在生成差异时忽略。



我发现这个与svn一样的vcs的关键区别之一(连同暂存和忽略目录)。

如果你想包含未跟踪的文件, git add 它们。



如果您不希望它们在您的回购中,请将它们添加到您的 .gitignore (请参阅 git ignore --help )。这适用于C目标文件或python .pyc 文件。



为什么我得不到git diff 之后添加?!



所以这个略有不同。如果您执行 git status ,您将看到该文件现在位于暂存区域中。这是您将要提交的文件的区域。



当您将 git添加一个新文件放入Git回购它跳过工作副本,并直接进入暂存区。这是有道理的, git add 总是将文件移入暂存区域,无论它是被跟踪的还是未被跟踪的。

要查看上次签入与暂存区域之间的差异,请执行 git diff --cached

要查看暂存区域与工作副本之间的差异,请执行 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 repo 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)

Let's see a diff of test.txt:

$ git diff

This gives no output!

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 stackoverflow tell me to git add some files so I do:

$ git add .
$ git diff

Still nothing!

Git GUI shows the changes.

git status -v shows the changes.

But for some reason git diff doesn't show anything.

So my questions are:

  1. How, in plain English, does git diff work?
  2. How can I show a diff of all the changes I've made (unstaged and staged)?

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.

解决方案

Why do you get no git diff before adding?

git does not treat files on 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 .).

There is no output to git diff because git sees no changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.

I found this one of the key differences to vcs like svn (along with staging and ignoring directories).

If you want the untracked files to be included, git add them.

If you don't want them in you're repo add them to you're .gitignore (see git ignore --help). This is good for C object files or python .pyc files.

Why do I get no git diff after adding?!

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.

When you git add a new file into the git repo it skips the working copy and does straight into the staging area. This make sense in a way, git add always moves files into staging area whether it is tracked or untracked.

To see the differences between the last check in and the staging area do git diff --cached.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆