git - 我可以使用它的索引而不是它的路径来引用“git diff path/to/file”中的脚本吗?
问题描述
我确实经常想快速检查我所做的更改。使用git status
通常如下所示:
$ git status
On branch develop
Your branch is ahead of 'develop' by 2 commits.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Assets/_Project/Scripts/Controls/ControllerManager.cs
modified: Assets/_Project/Scripts/UI/TabletManager.cs
no changes added to commit (use "git add" and/or "git commit -a")
要检查我所做的更改,我必须使用git diff Assets/_Project/Scripts/UI/TabletManager.cs
文件的完整路径,这些路径通常很长。但由于我经常使用这个功能,只更改了一些脚本,我想知道是否有类似快速访问选项的东西?也许通过传递修改文件的索引?喜欢git diff 1
查看 TabletManager 中所做的更改而不是完整路径。
解决方案
我不认为 git 有你想要的快速访问选项,因为大多数时候自动完成就足够了,正如@torek 在评论中告诉你的那样。
如果你真的想要这个功能,你可以自己创建它。
首先创建一个专用于 git 扩展的文件夹和
cd
它创建一个脚本文件并将其命名为
git-easydiff
. 现在我将它添加为本地别名,但您甚至可以使用自定义命令扩展 git,这里描述了如何。顺便说一句,一个可能的脚本可能是:#!/bin/bash changed_files=( $(git diff --name-only) ) for ((i = 0; i < ${#changed_files[@]}; i++)) do echo "$i - ${changed_files[$i]}" done; read -p "Index of file to git-diff: " git diff ${changed_files[$REPLY]}
现在别名
git config alias.easydiff '!/directory_with_git_extensions/git-easydiff'
!
开头是必要的,因为该命令不是 git 命令。
您可以将其称为git easydiff
,输出为:
0 - file1
1 - file2
Index of file to git-diff: 1
... diff for file2 ...
推荐阅读
- r - 下采样以均衡因子水平对的计数?
- hyperledger-fabric - 数据收集配置文件:配置文件必须在所有组织中都相同吗?
- r - 将xml格式转换为r中的数据框
- c# - DefaultHttpContext 在集成测试中测试身份验证
- c - 在 c 中使用套接字读取和显示内容
- python - 我如何在 Bokeh 中两次放置相同的 x 轴
- javascript - 在打印窗口中打开 Blob 文件
- firebase - 如何检查用户是否验证邮件然后让登录?
- azure - Azure SQL 权限:如何允许使用 Query Performance Insight,但不更改定价层等设置?
- windows - 尝试更新 Windows 中另一个文件夹中文件的文件时间/日期