简体   繁体   中英

How to get a git diffs file list without the deleted ones?

Currently I use this command to get a list of changed files between the develop and master branches:

git diff remotes/origin/master origin/develop --name-only > diffs.txt

Is there a way to exclude files that I deleted on the develop ?

TL;DR: --diff-filter=d .

Longer, but still not very long: See the --diff-filter option. In particular, diff-filter=AM , for instance, keeps only those entries whose status is either A or M. These letter codes are the same as the ones shown by git diff --name-status (and for that matter, by git status --short )—so to show only deleted files, you'd want --diff-filter=D .

Uppercase letters are inclusive, so if you want everything except D, you could use --diff-filter=ABCMRTUX , which is every possible code except D, but there's a shorter variant: lowercase means exclude , so --diff-filter=d means everything except status code D , which is of course what you want.

Note that several codes should never occur for many cases, eg, U (unmerged) can only occur during a conflicted merge and X (unknown) should never occur at all (it's a placeholder for Git to announce a self-detected bug). Codes B and C can only occur if you turn on the corresponding options. Code R occurs only if you turn on rename detection, but it is now on by default in Git 2.9 and later. Code T is rare: it means a regular file was replaced by a symlink, or vice versa, or that what was a submodule is now a regular file or symlink, or vice versa.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM