To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit:
git diff COMMIT~ COMMIT will show you the difference between that COMMIT's ancestor and the COMMIT. See the man pages for git diff for details about the command and gitrevisions about the ~ notation and its friends.
Alternatively, git show COMMIT will do something very similar. (The commit's data, including its diff - but not for merge commits.) See the git show manpage.
(also git diff COMMIT will show you the difference between that COMMIT and the head.)
To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit:
git diff COMMIT~ COMMIT will show you the difference between that COMMIT's ancestor and the COMMIT. See the man pages for git diff for details about the command and gitrevisions about the ~ notation and its friends.
Alternatively, git show COMMIT will do something very similar. (The commit's data, including its diff - but not for merge commits.) See the git show manpage.
(also git diff COMMIT will show you the difference between that COMMIT and the head.)
As mentioned in "Shorthand for diff of git commit with its parent?", you can also use git diff with:
git diff COMMIT^!
or
git diff-tree -p COMMIT
With git show, you would need (in order to focus on diff alone) to do:
git show --color --pretty=format:%b COMMIT
The COMMIT parameter is a commit-ish:
A commit object or an object that can be recursively dereferenced to a commit object. The following are all commit-ishes: a commit object, a tag object that points to a commit object, a tag object that points to a tag object that points to a commit object, etc.
See gitrevision "SPECIFYING REVISIONS" to reference a commit-ish.
See also "What does tree-ish mean in Git?".
Can I see all of my changes before I push them and open a PR?
git - How do I list all the files in a commit? - Stack Overflow
How to see changes in git commits, before pushing them | Drupal.org
how does git know what change you're commiting?
Videos
I'm pretty new to git and I got the basic workflow down. Now I'm trying to improve my skills a bit with git.
Is there some easy way for me to review all of my changes before I push to a remote branch and open a PR?
It would be nice to make sure I didn't forget to remove any unnecessary comments and code. The main thing I could do is simply open the PR and check on Github "files changed" and review it there and do another commit and push if I need to clean things up.
But I'm not sure if there's a way to do this before the PR is even opened. I'm using Android Studio btw so if there's a way in Android Studio (which is basically IntelliJ) then that would be good.
Preferred Way (because it's a plumbing command; meant to be programmatic):
$ git diff-tree --no-commit-id --name-only bd61ad98 -r
index.html
javascript/application.js
javascript/ie6.js
Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)
$ git show --pretty="" --name-only bd61ad98
index.html
javascript/application.js
javascript/ie6.js
- The
--no-commit-idsuppresses the commit ID output. - The
--prettyargument specifies an empty format string to avoid the cruft at the beginning. - The
--name-onlyargument shows only the file names that were affected (Thanks Hank). Use--name-statusinstead, if you want to see what happened to each file (Deleted, Modified, Added) - The
-rargument is to recurse into sub-trees
If you want to get the list of changed files:
git diff-tree --no-commit-id --name-only -r <commit-ish>
If you want to get the list of all files in a commit, you can use
git ls-tree --name-only -r <commit-ish>