ingenious ingenious - 1 year ago 70
Git Question

how to get latest commited files in Git

I want get latest changed files of my repository.

to do it:

I have run this command to get latest Commit ID:

git log --format="%H" -n 1

and then I paste output to this command:

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT "PREV_COMMAND_OUTPUT" | xargs tar -rf changedFiles.tar

Now, how I can merge These commands and pass output if first output as argument of second command?


Answer Source

If you are on linux (OSX might also work) and have access to a real shell (sorry, windows won't work) you can use command substitution:

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $(git log --format="%H" -n 1) | xargs tar -rf changedFiles.tar


git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT `git log --format="%H" -n 1` | xargs tar -rf changedFiles.tar

But since you're always using the last commit ID, you might as well just replace the whole command with HEAD

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD | xargs tar -rf changedFiles.tar
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download