Jak wyświetlić listę wszystkich plików w commicie?

Szukam prostego polecenia git, które zapewnia ładnie sformatowaną listę wszystkich plików, które były częścią commita podanego przez hash (SHA1), bez zbędnych informacji.

Próbowałem:

git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d

Chociaż zawiera listę plików, zawiera również niechciane informacje o różnicach dla każdego z nich.

Czy istnieje inne polecenie git, które dostarczy tylko listę, którą chcę, abym mógł uniknąć parsowania jej z wyjścia git show?

 2242
Author: Jacek Laskowski, 2009-01-08

26 answers

Preferowany sposób (ponieważ jest to komenda ; ma być programowa):

$ git diff-tree --no-commit-id --name-only -r bd61ad98
index.html
javascript/application.js
javascript/ie6.js

Inny sposób (mniej preferowany dla skryptów, ponieważ jest to polecenie ; przeznaczone dla użytkownika)

$ git show --pretty="" --name-only bd61ad98    
index.html
javascript/application.js
javascript/ie6.js

  • --no-commit-id wyłącza wyjście ID zatwierdzenia.
  • argument --pretty określa pusty łańcuch formatu, aby uniknąć błędu na początku.
  • argument --name-only pokazuje tylko nazwy plików, których dotyczy problem (Dzięki Hank).
  • argumentem -r jest rekurencja do Pod-drzew
 2964
Author: Ryan McGeary,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-07 19:18:14

Jeśli chcesz uzyskać listę zmienionych plików:

git diff-tree --no-commit-id --name-only -r <commit-ish>

Jeśli chcesz uzyskać listę wszystkich plików w commicie, możesz użyć

git ls-tree --name-only -r <commit-ish>
 193
Author: Jakub Narębski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-18 12:48:24

Zakładam, że gitk nie jest do tego pożądane. W takim przypadku spróbuj git show --name-only <sha>.

 181
Author: Hank Gay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-01-08 12:34:49

Osobiście używam kombinacji --stat i --oneline z show komend:

git show --stat --oneline HEAD
git show --stat --oneline b24f5fb
git show --stat --oneline HEAD^^..HEAD

Jeśli nie lubisz / nie chcesz statystyk dodawania/usuwania, możesz zastąpić --stat --name-only

git show --name-only --oneline HEAD
git show --name-only --oneline b24f5fb
git show --name-only --oneline HEAD^^..HEAD
 121
Author: Tuxdude,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-24 15:15:30

Możesz również zrobić

git log --name-only

I możesz przeglądać różne commity, komunikaty commitów i zmienione pliki.

Wpisz q, aby odzyskać monit.

 58
Author: Indu Devanath,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-02 06:35:56

Ostatnio musiałem wymienić wszystkie zmienione pliki pomiędzy dwoma commitami. Więc użyłem tego (również * Nix specific) polecenia

git show --pretty="format:" --name-only START_COMMIT..END_COMMIT | sort | uniq

Update : lub jak Ethan wskazuje poniżej

git diff --name-only START_COMMIT..END_COMMIT

Użycie --name-status będzie również zawierać zmiany (dodane, zmodyfikowane, usunięte itp.) OBOK KAŻDEGO pliku

git diff --name-status START_COMMIT..END_COMMIT
 57
Author: lunohodov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-21 07:25:13

Najprostsza forma:

git show --stat (hash)

To jest łatwiejsze do zapamiętania i da Ci wszystkie potrzebne informacje.

Jeśli naprawdę chcesz tylko nazwy plików, możesz dodać opcję --name-only.

git show --stat --name-only (hash)

 49
Author: VaTo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-17 04:11:51

Używamzmienionego aliasu a dość często. Aby go ustawić:

git config --global alias.changed 'show --pretty="format:" --name-only'

Wtedy:

git changed (lists files modified in last commit)   
git changed bAda55 (lists files modified in this commit)
git changed bAda55..ff0021 (lists files modified between those commits)

Podobne polecenia, które mogą być przydatne:

git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
git show --name-only
 45
Author: takeshin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-30 07:31:44

Użycie standardowego polecenia git diff (również dobre dla skryptów):

git diff --name-only <sha>^ <sha>

Jeśli chcesz również podać status zmienionych plików:

git diff --name-status <sha>^ <sha>

To działa dobrze z Merge commit.

 35
Author: vquintans,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-10 10:39:43
$ git log 88ee8^..88ee8 --name-only --pretty="format:"
 23
Author: Pat Notz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-01-08 14:11:28

Użyj

git log --name-status

Pokaże Ci identyfikator zatwierdzenia, wiadomość, zmienione pliki oraz czy zostały zmodyfikowane, utworzone, dodane lub usunięte. Coś w rodzaju "all-in-one".

 17
Author: alpha_989,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-15 16:42:35

OK, istnieje kilka sposobów na wyświetlenie wszystkich plików w danym commicie...

Aby zmniejszyć info i pokazać tylko nazwy plików, które zostały zatwierdzone, możesz po prostu dodać znacznik --name-only lub --name-status..., te flagi po prostu pokazują nazwy plików, które różnią się od poprzednich commitów, jak chcesz...

Więc możesz zrobić git diff Po --name-only, z dwoma hashami commit po <sha0> <sha1>, coś jak poniżej:

git diff --name-only 5f12f15 kag9f02 

Tworzę również poniższy obrazek, aby pokazać wszystkie kroki do przejść w takiej sytuacji:

git diff --name-only 5f12f15 kag9f02

 16
Author: Alireza,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-07 02:27:25

Używam tego, aby uzyskać listę zmodyfikowanych plików pomiędzy dwoma zestawami zmian:

git diff --name-status <SHA1> <SHA2> | cut -f2
 15
Author: user135507,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-03-28 07:37:53

Lubię używać

git show --stat <SHA1>^..<SHA2>
 15
Author: Michael De Silva,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-03 08:12:26
git show --name-only commitCodeHere
 12
Author: George Oikonomou,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-12 13:47:31

Podoba mi się:

git diff --name-status <SHA1> <SHA1>^
 11
Author: skiphoppy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-08-12 18:17:31

Istnieje również git whatchanged, który jest bardziej niski niż git log

NAME
       git-whatchanged - Show logs with difference each commit introduces

Wyświetla podsumowanie zatwierdzeń z listą plików pod nim z ich trybami i jeśli są dodane (A), usunięte (D) lub zmodyfikowane(M);

$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363

Dałby coś w stylu:

commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <[email protected]>
Date:   Tue Sep 29 17:23:22 2015 +0200

    added fb skd and XLForm

:000000 100644 0000000... 90a20d7... A  Pods/Bolts/Bolts/Common/BFCancellationToken.h
:000000 100644 0000000... b5006d0... A  Pods/Bolts/Bolts/Common/BFCancellationToken.m
:000000 100644 0000000... 3e7b711... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
:000000 100644 0000000... 9c8a7ae... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
:000000 100644 0000000... bd6e7a1... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
:000000 100644 0000000... 947f725... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
:000000 100644 0000000... cf7dcdf... A  Pods/Bolts/Bolts/Common/BFDefines.h
:000000 100644 0000000... 02af9ba... A  Pods/Bolts/Bolts/Common/BFExecutor.h
:000000 100644 0000000... 292e27c... A  Pods/Bolts/Bolts/Common/BFExecutor.m
:000000 100644 0000000... 827071d... A  Pods/Bolts/Bolts/Common/BFTask.h
...

Wiem, że ta odpowiedź nie pasuje do " bez zbędnych informacji.", ale nadal uważam, że ta lista jest bardziej przydatna niż tylko nazwy plików.

 11
Author: Koen.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-14 11:05:59

Użyj prostej komendy jednowierszowej, jeśli chcesz tylko zmienić listę plików w ostatnim zatwierdzeniu:

git diff HEAD~1 --name-only
 10
Author: Developer-Sid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-18 22:34:44

Lista plików, które zostały zmienione w zatwierdzeniu:

git diff --name-only SHA1^ SHA1

To nie pokazuje wiadomości dziennika, dodatkowych linii nowych ani żadnego innego bałaganu. Działa to dla każdego commita, nie tylko bieżącego. Nie jestem pewien, dlaczego nie zostało jeszczecałkiem wspomniane, więc dodaję.

 9
Author: Newtonx,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-28 00:55:26

Wyświetl dziennik.

COMMIT może być pusty ("") lub skrócony sha-1 lub SHA-1.

git log COMMIT -1 --name-only

Wyświetli listę tylko Plików, bardzo przydatnych do dalszego przetwarzania.

git log COMMIT -1 --name-only --pretty=format:"" | grep "[^\s]"
 8
Author: thefreshteapot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-09 10:17:41

Znalazłem idealną odpowiedź na to:

git show --name-status --oneline <commit-hash>

Abym mógł wiedzieć

which files were just modified M

Which files were newly added , A

Which files were deleted , D
 7
Author: Ijaz Khan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-01 21:51:00

Kombinacja "git show --stat" (dzięki Ryan) i kilka komend sed powinna przyciąć dane dla Ciebie:

git show --stat <SHA1> | sed -n "/ [\w]\*|/p" | sed "s/|.\*$//"

, który wytworzy tylko listę zmodyfikowanych plików.

 6
Author: seanhodges,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-09 10:17:13

Istnieje prosta sztuczka do wyświetlenia jako lista plików, wystarczy dodać : po hash.

git show 9d3a52c474:

Możesz wtedy wiercić,

git show 9d3a52c474:someDir/someOtherDir

Jeśli trafisz na plik, otrzymasz wersję raw pliku; która czasami jest tym, czego chcesz, jeśli szukasz tylko ładnego odniesienia lub kluczowych fragmentów kodu (diffs może sprawić, że wszystko będzie bałagan),

git show 9d3a52c474:someDir/someOtherDir/somefile

Jedyną wadą tej metody jest to, że nie wyświetla łatwo drzewa plików.

 6
Author: srcspider,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-26 11:59:32
git show HEAD@{0}

Works fine for me

 2
Author: Bruce,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-09 10:16:50

Pomyślałem, że podzielę się streszczeniem mojego pseudonimu.. również uważam, że używanie' zsh ' jest Świetne z git it chroma keys wszystko ładnie i mówi, że chcesz gałąź są przez cały czas, zmieniając wiersz polecenia.

Dla tych z SVN - u to się przyda: (jest to połączenie pomysłów z różnych wątków, przypisuję sobie tylko umiejętność kopiowania/wklejania)

.gitconfig:
        ls = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative --name-status

>>git ls
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker| 
| A     icds.xcodeproj/project.pbxproj
| A     icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata
| A     icds/AppDelegate.m
| A     icds/Assets.xcassets/AppIcon.appiconset/Contents.json

* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker| 
| D     Classes/AppInfoViewControler.h
| D     Classes/AppInfoViewControler.m
| D     Classes/CurveInstrument.h


.gitconfig: 
       lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>>git lt
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker
* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker
* 778bda6 - Cleanup for new project (11 hours ago) Jim Zucker
* 7373b5e - clean up files from old version (11 hours ago) Jim Zucker
* 14a8d53 - (tag: 1.x, origin/swift, origin/master, master) Initial Commit (16 hours ago) Jim Zucker


.gitconfig
lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>> git lt

commit 99f21a61de832bad7b2bdb74066a08cac3d0bf3c
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:23:10 2015 -0800

    New Files from xcode 7

A       icds.xcodeproj/project.pbxproj
A       icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata


commit e0a1bb6b59ed6a4f9147e894d7f7fe00283fce8d
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:17:00 2015 -0800

    Move everything to old

D       Classes/AppInfoViewControler.h
D       Classes/AppInfoViewControler.m
D       Classes/CurveInstrument.h
D       Classes/CurveInstrument.m
 0
Author: Jim Zucker,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-02 17:40:27

To powinno zadziałać:

git status

Pokaże to, co nie jest wystawione, a co jest wystawione.

 -1
Author: 4067098,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-03-08 00:53:14