- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用 git mv
移动或重命名文件时,git 在全局 diff 输出中显示移动/重命名操作:
me@myhost:~/test$ git mv foo.txt bar.txt
me@myhost:~/test$ git diff --staged
diff --git a/foo.txt b/bar.txt
similarity index 100%
rename from foo.txt
rename to bar.txt
但是,当我在文件上调用 git diff
时,它显示为新文件:
me@myhost:~/test$ git diff --staged bar.txt
diff --git a/bar.txt b/bar.txt
new file mode 100644
index 0000000..fad95f3
--- /dev/null
+++ b/bar.txt
@@ -0,0 +1 @@
+Hey there!
为什么此文件的 git diff
输出会因我是否使用文件名调用它而有所不同?当我传递文件名时,是否有标志或其他方式来查看重命名/移动状态?
Stack Overflow 上的大多数类似问题都建议在调用中添加 --find-renames
参数。不过,这似乎是我的默认行为,因为没有参数的 git diff
已经正确显示了重命名。但是,将 --find-renames
传递给带有文件名的第二次调用并没有什么不同。
最佳答案
请注意,为简单起见,我们假设您提交了更改并正在比较提交;无论您事先使用 --staged
还是之后使用提交,结果都是相同的。
Why is the output of git diff for this file different depending on whether I call it with or without the filename?
将文件规范视为可以通过其查看差异的镜头。
当完整地查看这两个提交时,Git 会看到:
Git 看到 F1 和 F2 指向同一个 blob,因为 F1 消失了,而 F2 出现了同一个 blob,Git 可以推断这是一个重命名。如果该文件也被编辑过,Git 可以进行试探法(顺便说一下,这是可配置的),以确定 blob 之间的差异是否足够接近以仍将其称为重命名。
当通过文件名镜头查看两个提交时,Git 看到:
Git 将此视为添加。
你能做什么?
您可以将镜头放大以包含两个文件名。使用您的示例语法进行移动,请考虑以下语句:
git diff --staged -- foo.txt # specify only the old file shows a delete
git diff --staged -- bar.txt # specify only the new file shows an add
git diff --staged -- foo.txt bar.txt # specify both shows a rename
或者在你提交之后,这里是比较当前和之前提交的类似语法:
git diff @~1 @ -- foo.txt # specify only the old file shows a delete
git diff @~1 @ -- bar.txt # specify only the new file shows an add
git diff @~1 @ -- foo.txt bar.txt # specify both shows a rename
这样做的明显缺点是您还必须知道以前的名字。根据您最终要实现的目标,也许您可以将多个命令链接在一起以解析前后文件名,并将它们都用作差异文件规范。下面是一个示例起点,向您展示了仅针对全局镜头的重命名:
git diff --staged --name-status -R
# or
git diff @~1 @ --name-status -R
这可能会导致你做这样的事情(使用 Bash):
git diff --staged -- $(echo $(git diff --staged --name-status -R | grep bar.txt) | cut -d' ' -f 2-)
# or
git diff @~1 @ -- $(echo $(git diff @~1 @ --name-status -R | grep bar.txt) | cut -d' ' -f 2-)
这是一个很棒的question and answer详细信息 diff filter options .
关于git - 在单个文件上使用 git diff 显示重命名/移动状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71268388/
只是想知道 Jquery Mobile 是否足够稳定以用于实时生产企业移动应用程序。 有很多 HTML5 框架,因为我们的团队使用 JQuery 已经有一段时间了,我们更愿意使用 Jquery 移动框
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 3 年前。 Improve t
所以我尝试在 JavaScript 中对元素进行拖放。我使用的视频教程在这里; https://www.youtube.com/watch?v=KTlZ4Hs5h80 。我已经按照它的说明进行了编码,
无法在移动 iOS(safari 和 chrome)上自动播放以前缓存的 mp3 音频 我正在 Angular 8 中开发一个应用程序,在该应用程序的一部分中,我试图在对象数组中缓存几个传入的音频 m
Git 基于内容而不是文件,所以我目前理解以下行为,但我想知道是否有特殊选项或 hack 来检测此类事情: git init mkdir -p foo/bar echo "test" foo/a.tx
我正在寻找语义 ui 正确的类来隐藏例如移动 View 中的 DIV。在 Bootstrap 中,我们有“visible-xs”和“hidden-xs”。 但是在语义ui上我只找到了“仅移动网格” 最
我正在使用 ubuntu 和 想要移动或复制大文件。 但是当我与其他人一起使用服务器时,我不想拥有所有内存并使其他进程几乎停止。 那么有没有办法在内存使用受限的情况下移动或复制文件? 最佳答案 如果你
这些指令有什么区别?以 ARM9 处理器为例,它不应该是: ASM: mov r0, 0 C: r0 = 0; ASM: ld r0, 0 C: r0 = 0; ? 我不知道为什么要使用一个或另一个:
我有一个文件夹,其中包含一些随机命名的文件,其中包含我需要的数据。 为了使用数据,我必须将文件移动到另一个文件夹并将文件命名为“file1.xml” 每次移动和重命名文件时,它都会替换目标文件夹中以前
我经常在 IB/Storyboard 中堆叠对象,几乎不可能拖动其他对象后面的对象而不移动前面的对象。无论如何我可以移动已经选择但位于其他对象后面的对象吗?当我尝试移动它时,它总是选择顶部的对象,还是
几个月前,我看到 Safari 7 允许推送通知,它似乎是一个非常有用的工具,除了我看到的每个示例都专注于桌面浏览,而不是移动设备。 Safari 推送通知是否可以在移动设备上运行,如果没有,是否有计
我有一个简单的 View 模型,其中包含修改后的 ObservableCollection使用 SynchronizationContext.Current.Send在 UI 线程上执行对集合的更改。
关于cassandra创建的数据文件和系统文件的位置,我需要移动在“cassandra.yaml”配置文件中设置的“commitlog_directory”、“data_file_directorie
我有这个代码 $(function() { var message = 'Dont forget us'; var original; var txt1 = ' - '; $(wind
我的客户报告说他的网站有一个奇怪的问题。该网站的 URL 是 your-montenegro.me 在 基于 Android 的浏览器 上加载时,页面底部会出现一个奇怪的空白区域。以下是屏幕截图: 华
我有这个 HTML 标记: Express 300 bsf Sign Up 我需要将元素从 DOM 上的一个
我有一个可重新排序的 TableView (UITableView 实例)。尽管我已经实现了 UITableViewDataSource 方法: tableView:moveRowAtIndexPat
我的客户报告说他的网站有一个奇怪的问题。该网站的 URL 是 your-montenegro.me 在 基于 Android 的浏览器 上加载时,页面底部会出现一个奇怪的空白区域。以下是屏幕截图: 华
我需要在拖放或复制/剪切和粘贴(复制与移动)期间获取操作类型。它是一个 Swing 应用程序,并且实现了 TransferHandle。我在操作结束时需要此信息,在 importData 方法中。 对
我编写了一个具有 add 和 get 方法的 SortedIntList 类。 我调用以下四个方法: SortedIntList mySortedIntList = new SortedIntList
我是一名优秀的程序员,十分优秀!