由于官僚主义的原因,我需要为报告获得存储库中所有更改的文件的列表(我从现有源代码开始)。
我该怎么跑才能拿到这个列表?
由于官僚主义的原因,我需要为报告获得存储库中所有更改的文件的列表(我从现有源代码开始)。
我该怎么跑才能拿到这个列表?
当前回答
我需要在两次提交之间更改内容的文件列表(只添加,a,或修改,M),所以我使用:
git diff --name-only --diff-filter=AM <from_commit_hash> <to_commit_hash>
下面是git diff文档中不同的——diff-filter选项(参见man git diff):
--diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]] Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected. Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths. Note that not all diffs can feature all types. For instance, diffs from the index to the working tree can never have Added entries (because the set of paths included in the diff is limited by what is in the index). Similarly, copied and renamed entries cannot appear if detection for those types is disabled.
如果你也想列出状态(例如A / M),将——name-only更改为——name-status:
git diff --name-status --diff-filter=AM <from_commit_hash> <to_commit_hash>
其他回答
unstaging modified列表可以使用git status和grep命令获取,如下所示。比如git status -s | grep M:
root@user-ubuntu:~/project-repo-directory# git status -s | grep '^ M'
M src/.../file1.js
M src/.../file2.js
M src/.../file3.js
....
使用git show可以得到类似的结果。为了查看包含文件列表的提交(就像它在git日志视图中一样),使用:
git show --name-only [commit-id_A]^..[commit-id_B]
其中[commit- id_a]是初始提交,[commit- id_b]是您想要显示的最后一次提交。
特别注意^符号。如果不这样做,commit-id_A信息将不会部署。
当我添加/修改/删除许多文件(自上次提交以来)时,我喜欢按时间顺序查看这些修改。
我用的是:
查询所有非暂存文件。 Git ls-files——other——modified——exclude-standard 获取每个文件的最后修改日期: 读取文件名时;执行echo -n "$(stat -c%y——$filename 2> /dev/null)”;echo $文件名;完成
尽管ruvim在评论中建议:
xargs -0 stat -c '%y %n' --
按时间顺序排列: 排序
别名使它更容易使用:
alias gstlast='git ls-files --other --modified --exclude-standard|while read filename; do echo -n "$(stat -c%y -- $filename 2> /dev/null) "; echo $filename; done|sort'
或者(多亏了ruvim,更短更高效)
alias gstlast='git ls-files --other --modified --exclude-standard|xargs -0 stat -c '%y %n' --|sort'
例如:
username@hostname:~> gstlast
2015-01-20 11:40:05.000000000 +0000 .cpl/params/libelf
2015-01-21 09:02:58.435823000 +0000 .cpl/params/glib
2015-01-21 09:07:32.744336000 +0000 .cpl/params/libsecret
2015-01-21 09:10:01.294778000 +0000 .cpl/_deps
2015-01-21 09:17:42.846372000 +0000 .cpl/params/npth
2015-01-21 12:12:19.002718000 +0000 sbin/git-rcd
我现在可以回顾我的修改,从最老的到最近的。
我需要在两次提交之间更改内容的文件列表(只添加,a,或修改,M),所以我使用:
git diff --name-only --diff-filter=AM <from_commit_hash> <to_commit_hash>
下面是git diff文档中不同的——diff-filter选项(参见man git diff):
--diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]] Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected. Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths. Note that not all diffs can feature all types. For instance, diffs from the index to the working tree can never have Added entries (because the set of paths included in the diff is limited by what is in the index). Similarly, copied and renamed entries cannot appear if detection for those types is disabled.
如果你也想列出状态(例如A / M),将——name-only更改为——name-status:
git diff --name-status --diff-filter=AM <from_commit_hash> <to_commit_hash>
一些过滤器是为我工作在GitHub动作取决于类型(pull_request或合并为主):
git --no-pager diff --name-only --diff-filter=ACMRT ${{github.event.pull_request.base.sha}} ${{ github.event.pull_request.head.sha }}
git --no-pager diff --name-only --diff-filter=ACMRT ${{github.event.pull_request.base.sha}} ${{github.sha}}
git log -m -1 --name-only --pretty="format:" ${{ github.sha }}
试试这些,看看哪一个适合你的需要。