Use git filter by type of change

less than 1 minute read

Which files have been deleted or modified? Use git diff --diff-filter=[(A|C|D|M|R|T|U|X|B)…​[*]]

# Select all files
$ git diff --name-status  HEAD~1
M       package-lock.json
M       package.json
M       src/App.vue
M       src/plugins/vuetify.ts
M       src/router/index.ts
A       src/service/index.js
M       src/store/index.ts
D       src/views/Home.vue
A       src/views/Login.vue
M       tsconfig.json
M       vue.config.js

Include

Use Upper-case.

# Select modified files only
$ git diff --name-status --diff-filter=M HEAD~1
M       package-lock.json
M       package.json
M       src/App.vue
M       src/plugins/vuetify.ts
M       src/router/index.ts
M       src/store/index.ts
M       tsconfig.json
M       vue.config.js

Exclude

Use lower-case.

# Select not modified files only
$ git diff --name-status --diff-filter=m HEAD~1
A       src/service/index.js
D       src/views/Home.vue
A       src/views/Login.vue

Reference: git diff –diff-filter

Tags:

Categories:

Updated:

Leave a comment