新/修改/删除文件的 GIT 列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9915543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:19:33  来源:igfitidea点击:

GIT list of new/modified/deleted files

gitfilelistdiff

提问by Jean

Is there a way to get the list of all new/deleted/modified directories/files in local/remote repository w.r.t each other in GIT ?

有没有办法在 GIT 中获取本地/远程存储库中所有新/删除/修改的目录/文件的列表?

回答by Alex Sharapov

The best way to list these file is using git status --porcelain

列出这些文件的最佳方法是使用 git status --porcelain

For example: To remove previously deleted files:

例如: 要删除以前删除的文件:

git status --porcelain | awk 'match(, "D"){print }' | xargs git rm

回答by Lily Ballard

I'm not sure what you mean by with respect to each other, but if you want an individual listing (e.g. all modified files) you can use git ls-fileswith the right flags (for modified files it's -m). If you want all of this info at once, you can use git status --porcelainto get a script-parsable output of the status.

我不确定你对彼此的意思,但如果你想要一个单独的列表(例如所有修改过的文件),你可以使用git ls-files正确的标志(对于修改过的文件,它是-m)。如果您想要一次git status --porcelain获得所有这些信息,您可以使用来获取状态的脚本可解析输出。

回答by Trident D'Gao

Use the dry-run (-n) option of git add:

使用干运行 (-n) 选项git add

git add -A -n

git add -A -n

回答by sparrow

One way to do this is with the whatchangedcommand:

一种方法是使用以下whatchanged命令:

$ git whatchanged

This shows which files changed for each commit in the tree and can be used to look at specifics as well. Take a look at git help whatchanged

这显示了为树中的每个提交更改了哪些文件,也可用于查看细节。看一眼git help whatchanged

回答by Cascabel

What you probably want is something like:

你可能想要的是这样的:

git fetch     # update what you know about the remote repo
git diff --name-status master origin/master

But it's pretty difficult to tell exactly what branches you want to diff from your question.

但是很难确切地说出您想要与您的问题不同的分支。

回答by LeandroN.

To get just file names and status of the currently changed files you can simply:

要获取当前更改文件的文件名和状态,您可以简单地:

git diff --name-status

git diff --name-status

You will get the bare output like this:

你会得到这样的裸输出:

M       a.txt
M       b.txt

Now, pipe the output to cutto extract the second column:

现在,将输出通过管道传输cut到以提取第二列:

git diff --name-status | cut -f2

git diff --name-status | cut -f2

Then you'll have just the file names:

然后你将只有文件名:

a.txt
b.txt

回答by Lefan

use with command --name-status

与命令一起使用 --name-status

example with tags:

带标签的例子:

git diff v1.0.1 v1.0.2 --name-status

example with commits:

提交示例:

git diff b79810fc4d be69e41d1c --name-status

it will list all the updated files with their statuses: M- modified D- deleted A- added

它将列出所有更新的文件及其状态: M- 修改 D- 删除 A- 添加