diff --git a/README.md b/README.md index f7cd25b..cf5c925 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ _349 TILs and counting..._ - [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md) - [Renaming A Branch](git/renaming-a-branch.md) - [Resetting A Reset](git/resetting-a-reset.md) +- [Show All Commits For A File Beyond Renaming](git/show-all-commits-for-a-file-beyond-renaming.md) - [Show The diffstat Summary Of A Commit](git/show-the-diffstat-summary-of-a-commit.md) - [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md) - [Staging Changes Within Vim](git/staging-changes-within-vim.md) diff --git a/git/show-all-commits-for-a-file-beyond-renaming.md b/git/show-all-commits-for-a-file-beyond-renaming.md new file mode 100644 index 0000000..3c692cb --- /dev/null +++ b/git/show-all-commits-for-a-file-beyond-renaming.md @@ -0,0 +1,45 @@ +# Show All Commits For A File Beyond Renaming + +By including `-- ` with a `git log` command, we can list all the +commits for a file. The following is an example of such a command with some +formatting and file names. + +```bash +> git log --name-only --pretty=format:%H -- README.md +4e57c5d46637286731dc7fbb1e16330f1f3b2b7c +README.md + +56955ff027f02b57212476e142a97ce2b7e60efe +README.md + +5abdc5106529dd246450b381f621fa1b05808830 +README.md +``` + +What we may not realize though, is that we are missing out on a commit in +this file's history. At one point, this file was renamed. The command above +wasn't able to capture that. + +Using the `--follow` flag with a file name, we can list all commits for a +file beyond renaming. + +```bash +> git log --name-only --pretty=format:%H --follow README.md +4e57c5d46637286731dc7fbb1e16330f1f3b2b7c +README.md + +56955ff027f02b57212476e142a97ce2b7e60efe +README.md + +5abdc5106529dd246450b381f621fa1b05808830 +README.md + +ea885f458b0d525f673623f2440de9556954c0c9 +README.rdoc +``` + +This command roped in a commit from when `README.md` used to be called +`README.rdoc`. If you want to know about the *full* history of a file, this +is the way to go. + +[source](http://stackoverflow.com/questions/3701404/list-all-commits-for-a-specific-file)