Git diff没有列出对文件的特定更改?
我一直在尝试添加和提交,并使用Git diff没有列出对文件的特定更改?,git,Git,我一直在尝试添加和提交,并使用diff显示HEAD、index和working dir之间的差异。使用diff,我的理解是,它应该指定哪些文件已更改,但也应该指定文件之间的差异(例如,如果我将“hello”写入文件,当我运行diff时,它应该说+hello(或类似的东西),并比较两者) 但是,当我使用diff时,它只显示文件已更改;它无法显示这些变化是什么。为什么它不显示文件中的单个更改--我添加的实际文本,我删除的具体内容,等等。?如果diff不执行此操作,是否有可以使用的命令 多谢各位 为
diff
显示HEAD、index和working dir之间的差异。使用diff
,我的理解是,它应该指定哪些文件已更改,但也应该指定文件之间的差异(例如,如果我将“hello”写入文件,当我运行diff
时,它应该说+hello
(或类似的东西),并比较两者)
但是,当我使用diff
时,它只显示文件已更改;它无法显示这些变化是什么。为什么它不显示文件中的单个更改--我添加的实际文本,我删除的具体内容,等等。?如果diff
不执行此操作,是否有可以使用的命令
多谢各位
为了运行一个完整的测试,我删除了
.git
并运行了一个git init
,然后发现diff
并没有为diff
的所有三个变体显示diff(git diff
,git diff--cached
,以及git diff-HEAD
)。我使用的文件是t.txt
。这是我的控制台,我格式化了它的可读性<代码>>>是Powershell提示输入的地方,我在控制台中键入了输入;我边走边写评论,用>#
表示。这是我的控制台输出:
>> # Starting with nothing.
>> git status
fatal: Not a git repository (or any of the parent directories): .git
>> git init
Initialized empty Git repository in C:/Users/q/Documents/GitHub/.git/
>> ls
>> git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
>> echo "New file created." > t.txt
>> git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
t.txt
nothing added to commit but untracked files present (use "git add" to track)
>> git add .
>> git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: t.txt
>> #open t.txt and add a second line of text to it
>> git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: t.txt
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: t.txt
>> git diff
diff --git a/t.txt b/t.txt
index e7a4f8a..fe91a49 100644
Binary files a/t.txt and b/t.txt differ
>> #How can I see the exact change?
>> #Something like: '''
>> #
>> # + This is the added line.
>> #
>> # ''' in the diff?
>> # I can take this even further by making the first commit, modifying, then staging the file
# with `git add`, then editing again, and then run all three `git-diff`s
# (git diff, git diff --cached, git diff HEAD) and none of them will specify any actual
# changes in the files; Git still just lists the files that have discrepancies, without
# listing any of the detials about /what/ is actually different.
>> git add .
>> git commit -m "Committed with the second line."
[master (root-commit) 14acc45] Committed with the second line.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 t.txt
>> git diff
>> git log
commit 14acc455b16ba26cdea1661166b0ffc3fa089784
Author: q <q@gmail.com>
Date: Sat Nov 7 04:29:20 2015 -0800
Committed with the second line.
>> git diff HEAD
>> git diff HEAD^
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
>> #We change the file again to add a third line
>> git status
On branch master
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: t.txt
no changes added to commit (use "git add" and/or "git commit -a")
>> git diff
diff --git a/t.txt b/t.txt
index fe91a49..006c33a 100644
Binary files a/t.txt and b/t.txt differ
>> git diff HEAD
diff --git a/t.txt b/t.txt
index fe91a49..006c33a 100644
Binary files a/t.txt and b/t.txt differ
>> git add .
>> #Modify file again.
>> git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: t.txt
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: t.txt
>> git diff
diff --git a/t.txt b/t.txt
index 006c33a..57a6754 100644
Binary files a/t.txt and b/t.txt differ
>> git diff HEAD
diff --git a/t.txt b/t.txt
index fe91a49..57a6754 100644
Binary files a/t.txt and b/t.txt differ
>> git diff --cached
diff --git a/t.txt b/t.txt
index fe91a49..006c33a 100644
Binary files a/t.txt and b/t.txt differ
>>## But how do they differ?
从零开始。
>>git状态
致命:不是git存储库(或任何父目录):.git
>>git初始化
已在C:/Users/q/Documents/GitHub/.Git中初始化空Git存储库/
>>ls
>>git状态
论分行行长
初始提交
无需提交(创建/复制文件并使用“git add”跟踪)
>>echo“创建新文件”>t.txt
>>git状态
论分行行长
初始提交
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
t、 文本
提交时未添加任何内容,但存在未跟踪的文件(使用“git add”跟踪)
>>git添加。
>>git状态
论分行行长
初始提交
要提交的更改:
(使用“git rm--cached…”取消存储)
新文件:t.txt
>>#打开t.txt并在其中添加第二行文本
>>git状态
论分行行长
初始提交
要提交的更改:
(使用“git rm--cached…”取消存储)
新文件:t.txt
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
修改:t.txt
>>吉特差
diff——git a/t.txt b/t.txt
索引e7a4f8a..fe91a49 100644
二进制文件a/t.txt和b/t.txt不同
>>#我怎样才能看到确切的变化?
>>#类似于:“”
>> #
>>#+这是添加的行。
>> #
>>##“在差异中?”?
>>#我可以通过第一次提交、修改、然后暂存文件来进一步实现这一点
#使用'git add',然后再次编辑,然后运行所有三个'git diff'
#(git-diff,git-diff--cached,git-diff-HEAD),它们都不会指定任何实际的
#档案的变更;Git仍然只是列出有差异的文件,没有
#列出关于/什么/实际上不同的任何细节。
>>git添加。
>>git commit-m“用第二行提交”
[master(root提交)14acc45]使用第二行提交。
1个文件已更改,0个插入(+),0个删除(-)
创建模式100644 t.txt
>>吉特差
>>吉特日志
提交14ACC455B16BA26CDEA166116B0FFC3FA089784
作者:q
日期:2015年11月7日星期六04:29:20-0800
与第二行一起提交。
>>吉特压头
>>吉特压头^
致命:参数“HEAD^”不明确:未知修订或路径不在工作树中。
使用“---”将路径与修订分开,如下所示:
'吉特[…]-[…]'
>>#我们再次更改文件以添加第三行
>>git状态
论分行行长
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
修改:t.txt
未向提交添加任何更改(使用“git add”和/或“git commit-a”)
>>吉特差
diff——git a/t.txt b/t.txt
索引fe91a49..006c33a 100644
二进制文件a/t.txt和b/t.txt不同
>>吉特压头
diff——git a/t.txt b/t.txt
索引fe91a49..006c33a 100644
二进制文件a/t.txt和b/t.txt不同
>>git添加。
>>#再次修改文件。
>>git状态
论分行行长
要提交的更改:
(使用“git重置磁头…”取消分级)
修改:t.txt
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
修改:t.txt
>>吉特差
diff——git a/t.txt b/t.txt
索引006c33a..57a6754 100644
二进制文件a/t.txt和b/t.txt不同
>>吉特压头
diff——git a/t.txt b/t.txt
索引fe91a49..57a6754 100644
二进制文件a/t.txt和b/t.txt不同
>>git diff——缓存
diff——git a/t.txt b/t.txt
索引fe91a49..006c33a 100644
二进制文件a/t.txt和b/t.txt不同
>>##但它们有何不同?
如果文件太小,git不知道如何解释它(测试或二进制):请参阅“” 您可以使用以下命令强制文本差异:
git diff --text
(也可以作为文本)请参见,将二进制文件视为文本谢谢,这就是问题所在。顺便说一句,感谢您提供了关于配置Git以将其视为文本的链接——其中一个答案说,如果不保存在UTF-8中,将打乱前8000个块或其他东西。。。。无论如何,我检查并
echo“HI”>t.txt
保存为Unicode。打开记事本->另存为…->UTF-8完全解决了这个问题!