Baptiste Pernet
Baptiste Pernet

Reputation: 3384

Get the modified files

I want to have a list of modified files using a searching pattern

so far, I have done that

git log --pretty=oneline | grep SEARCH_TEXT | cut -d' ' -f1

to get all the concern commit. I could now use xargs and git log --pretty=oneline --name-only to have all the files and then sort | uniq at the end to make it clean, but I am not git and bash expert and I don't know how to do this.

Upvotes: 2

Views: 457

Answers (5)

klerk
klerk

Reputation: 396

with git log --pretty=oneline , you get ID-s of the commit's then you can check with the next command:

git show --name-only {sha-id}

also with: git diff-tree --no-commit-id --name-only -r <sha-id> with this you get the files modified and included in that particular commit, depends of the output and sorting

git diff-tree --no-commit-id --name-only -r <sha-id> |sort -r -n -k5

this will sort starting with largest files. The -n operator specifies "numeric" sorting as compared to alphabetic.

Upvotes: 2

Victor Henriquez
Victor Henriquez

Reputation: 1449

To continue with your bash scripting approach, you could do:

for i in `git log --pretty=oneline |  grep SEARCH_PATTERN | cut -d ' '
-f1 `; do git show --pretty="format:" --name-only $i; done | sort | uniq

Or using xargs:

git log --pretty=oneline |  grep SEARCH_PATTERN | cut -d ' ' -f1 | xargs git
show --pretty="format:" --name-only | sort | uniq

Upvotes: 2

Baptiste Pernet
Baptiste Pernet

Reputation: 3384

thanks for your help, I achieved what I wanted with this

git log --pretty=oneline | grep SEARCH_PATTERN | cut -d' ' -f1 | xargs git show --name-only --pretty=format: | sort | uniq

Upvotes: 0

kaman
kaman

Reputation: 376

If you want to list all modified files since the first commit you can use

git diff --name-only $(git rev-list --max-parents=0 HEAD)

and then you can sort or grep it as you want

Upvotes: 0

Tiago Lopo
Tiago Lopo

Reputation: 7959

If I understood well you want to create a list in the format [commit_id] [file(s)_changed]. It that's right try the following:

[root@TIAGO-TEST git]# git log --pretty=oneline| awk '{print $1}'|while read commit; do path=$(git show --name-only $commit | egrep -v '^(commit|Author|Date:|Merge:|^\s|$)'); echo $commit $path; done  
d8c86ba5feca19c7ca9dba4a60a7e5c5dd24d134
f2555bb80b190a7640ea7c1cbda76a5abfd61d17 config_example.cfg graph_explorer/validation.py
7750db9820af7c6ea8612a4d72a4ad22da9bb1d4 graph_explorer/assets/js/graph-explorer.js
201ac16e4aa1650155c58406cb93e4ec00ca0424 graph_explorer/preferences_color.py 
c89af43090de2528de6c5feb20a6388d535358c4 graph_explorer/templates/graphs.tpl
e5307533ee3da66eadb76f1108ada7a9a8b42f75 config_example.cfg
d42d45e2ce937b52699a5b58922c416f9b21db5d config_example.cfg graph_explorer/templates/snippet.graph.tpl 
a5ccfad2328fc8d24a9c117e901b36e720aa4e98 README.md config_example.cfg
4186cbcdeb79d8e85ae818f711841177fa33b560 graph_explorer/timeserieswidget
da46261fd5c8aa5352e73e97da95324285ef4245 graph_explorer/timeserieswidget

Once you have that list you can grep for whatever pattern you want.

Upvotes: 1

Related Questions