git get last commit id 1

git get last commit id

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

Here is what the above code is Doing:
1. git log –format=”%H” -n 1
– git log: Show the commit logs
– –format=”%H”: Only show the hash of the commit
– -n 1: Only show one commit hash
2. git diff-tree –no-commit-id –name-only -r $COMMIT
– git diff-tree: Show the changed files in a commit
– –no-commit-id: Don’t show the commit hash
– –name-only: Only show the file names
– -r: Recursive, get changed files from all subdirectories
– $COMMIT: Use the commit hash we got from the first command
3. xargs -I % sh -c ‘grep -H “” % | grep -v “Binary file”‘
– xargs: Execute the command for each line in the input
– -I %: The placeholder for the input. For each line of input, it’ll be
replaced with %
– sh -c: Execute the command with /bin/sh
– ‘grep -H “” % | grep -v “Binary file”‘: The command to execute. For each
line of input, it’ll be replaced with %
– grep -H “”: Print the filename and the matching lines. The matching
pattern is empty, so it’ll print all lines
– grep -v “Binary file”: Filter out any lines that match “Binary file”.
This is because git will place that string if a file is binary and
cannot be printed.

Similar Posts