- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在尝试添加和提交,并使用 diff
显示 HEAD、索引和工作目录之间的差异。使用 diff
,我的理解是它应该指定哪些文件已更改,但也应该指定文件之间的差异(例如,如果我将“hello”写入文件,它应该说 +hello
(或类似的东西)当我运行 diff
并比较两者时)。
当我使用 diff
时,但是,它只告诉我文件已更改;它没有显示这些变化是什么。为什么它不显示文件中的个别更改——我添加的实际文本、我具体删除的内容等等?如果diff
不这样做,是否有我可以使用的命令?
谢谢。
为了运行完整测试,我删除了 .git
并运行 git-init
, 然后找到 diff
没有显示 diff
的所有三个变体的差异( git diff
、 git diff --cached
和 git diff HEAD
)。我使用的文件是t.txt
.这是我的控制台,为了便于阅读,我对其进行了格式化; >>
是 Powershell 提示输入的地方,我在控制台中输入了该输入;评论是我去的时候写的,用>> # <comment>
表示.这是我的控制台输出:
>> # 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 不知道如何解释它(测试或二进制):参见“Why does Git treat this text file as a binary file?”
您可以强制文本差异:
git diff --text
(或者您可以将 configure it 作为文本)
关于Git diff 没有列出对文件的特定更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33583079/
我在我们的系统中使用了多种不同的查询,我们想要获取分页的“总”记录。 我所遵循的所有地方都遵循这种结构 - var query1 = "select SQL_CALC_FOUND_ROWS ...."
我是 diff 的新手。我过去用过它。但我想知道,是否可以使用 diff 来跟踪希伯来语中两个文件之间的差异?我想比较具有元音点和重音符号的圣经希伯来文文件。 最佳答案 我不知道有任何“差异”(文件比
在Word中,有一个选项可以比较两个文档并找出两个文档之间的差异。我正在寻找一个类似的功能来比较两个Powerpoint文档。理想情况下,它将列出不同的单个幻灯片,每个幻灯片之间版本之间的差异以及进行
Bizzaro-Diff!!! 有没有办法做一个只显示一组文件中相同部分的 bizzaro/inverse-diff? (即远超过 three files ) 奇怪的问题,我知道...但我正在将某人的
我将 git 与默认的 Ubuntu 12.04 软件包一起使用: git --version git version 1.7.9.5 我找不到任何可以让 git diff 打开外部差异工具的机制,它
这是我的树 ├── test │ ├── dir1 │ └── dir2 │ ├── file │ └── file2 └── test2 └── dir2
我在 source forge ( cocoa.diff ) 上找到了这个补丁,这意味着我可以使用 cocoa.diff 文件进行补丁。但是,我似乎无法弄清楚如何使用 .diff 文件。 谢谢你的帮助
我修改了某个文件的第 494 行,并使用 cvs diff -u4 来查看我修改的内容,cvs 输出如下内容: @@ -490,9 +490,9 @@ if (!(hPtr->hSta
我需要知道这两个补丁是否有效相同。 我有一个旧补丁文件和使用 unix diff 命令创建的新补丁文件。由于补丁创建时的时间戳,只是比较补丁会报告差异。 有没有办法(有差异?)可以可靠地告诉我这两个补
我有这样的东西 src/sim/simulate.cc 41d40 public: > 61,62c60,61 a.patch 用于创建补丁文件,尽管也可能会抛出一些其他开关(-N?)
我想知道是否有工具可以显示与 debian 打包相关的补丁中使用的 *.diff 文件。我需要从该工具中获得的是它可以只读取 diff 文件并显示随更改的行更改的实际文件,就像 kdiff 或 mel
主要有3个git diff版本: git diff - difference between WORKING DIRECTORY & STAGE git diff --staged - differe
根据 Ender 的 Applied Econometric Time Series ,变量 y 的二阶差分定义为: Pandas 提供了 diff 函数,它接收“periods”作为参数。尽管如此,
这是我的差异的开始部分。 #!/usr/bin/env python import fileinput import difflib import subprocess import sys # fo
有没有办法在 svn diff 或任何其他工具(基于 linux)到 仅显示空格/制表符更改 ?. 目的,我不希望 checkin 这些差异。如果工具可以捕获这些差异,我可以在 checkin 之前将
我正在尝试比较忽略回车符的文件 - diff -b 在任何其他 unix 上的表现令人钦佩。但是在这个 AIX 5.3 机器上: tst1:tst2$ od -c testfile 00000
这个问题已经有答案了: What does the “@@…@@” meta line with at signs in svn diff or git diff mean? (3 个回答) 已关闭
我在使用 git diff --word-diff 时遇到了问题。问题是当 diff 获取没有换行符的文件(单行文件)时,它会逐行区分。我想逐字区分。 以下是当我在没有换行符的情况下比较文件时发生的情
这个问题在这里已经有了答案: Highlight changed lines and changed bytes in each changed line (12 个答案) 关闭 7 年前。 给定一
我正在尝试使用两个大文件夹(〜7GB)创建一个补丁。 这是我的做法: $ diff -Naurbw . ../other-folder > file.patch 但可能由于文件大小而导致未创建补丁并给
我是一名优秀的程序员,十分优秀!