0
$ git log --name-status HEAD^..HEAD
commit 2ca5c13aba662df60ace9945b5110b7589f0aad2 (HEAD -> devops, origin/devops)
Author: Sample Name <samplename@asdfgt88p12.asdfe.net>
Date:   Wed Feb 6 17:18:30 2019 +0000

    removing unnecessary lines

M       dev/Jenkinsfile1
M       dev/JenkinsfileFind
M       dev/JenkinsfileCICD-DEV
M       dev/JenkinsfileIaC

git log --name-status HEAD^..HEAD command list files which are last committed. How can I export all these file names and path of the file names into a .csv file?

asur
  • 1,759
  • 7
  • 38
  • 81

1 Answers1

1

You can use one of the commands in "How to list only the file names that changed between two commits?"

git diff --name-only --diff-filter=M @~ > list.csv
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @VonC- When I execute the same command in ec2 AWS server I get below error. Any suggestion. Same command gets executed without issues in my local terminal. Error:= `fatal: ambiguous argument '@~': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'` – asur Feb 11 '19 at 11:44
  • @Kally That just means the Git version installed on EC2 AWS is an old one (older than 1.8.4): replace `@~` by `HEAD~`: see https://stackoverflow.com/a/964927/6309 – VonC Feb 11 '19 at 13:00
  • Thank you.. How can I also get diff for newly created files – asur Feb 12 '19 at 10:43
  • @Kally use AM instead of M in your diff-filter: see https://git-scm.com/docs/git-diff#git-diff---diff-filterACDMRTUXB82308203 – VonC Feb 12 '19 at 10:45
  • I am using command `git diff --name-only --diff-filter=AM @~ > list.csv`. But this command is only showing changes modified/created only to particular folder. Overall changes to repo is not showing up. How can git diff only to particular folder..? – asur Feb 12 '19 at 10:57
  • @Kally "How can git diff only to particular folder..": https://stackoverflow.com/a/8382054/6309. "Overall changes to repo is not showing up." Use the magic pathspec `:/` (that I describe in https://stackoverflow.com/a/33449169/6309): `git diff ... :/`. In your case: `git diff --name-only --diff-filter=AM @~ :/ > list.csv` – VonC Feb 12 '19 at 11:08
  • I want to check whether dags folder under my repo is modified/changed/added `git diff --name-only --diff-filter=M :/dags @~ > list.csv' Error:- `fatal: ambiguous argument ':/dags': both revision and filename Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'` – asur Feb 12 '19 at 11:15
  • @Kally I uses :/ at the end of the command: `git diff --name-only --diff-filter=M @~ :/dags > list.csv` – VonC Feb 12 '19 at 11:17
  • Still same error:( `fatal: ambiguous argument ':/dags': both revision and filename Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'` – asur Feb 12 '19 at 11:20
  • @Kally And with `it diff --name-only --diff-filter=M @~ -- :/dags > list.csv`? – VonC Feb 12 '19 at 11:23
  • @Kally If not, try: `git -C /path/to/your/repo diff --name-only --diff-filter=M @~ -- dags > list.csv` – VonC Feb 12 '19 at 11:23
  • Still no luck. I tried both commands. It creates list.csv file but with no info on it. – asur Feb 12 '19 at 11:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188272/discussion-between-vonc-and-kally). – VonC Feb 12 '19 at 11:29
  • @VonC-- You were very helpful.. Really thank you much for your suggestions. – asur Feb 12 '19 at 11:40