File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010For a steady stream of TILs from a variety of rocketeers, checkout
1111[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
1212
13- _ 744 TILs and counting..._
13+ _ 745 TILs and counting..._
1414
1515---
1616
@@ -175,6 +175,7 @@ _744 TILs and counting..._
175175- [ Dropping Commits With Git Rebase] ( git/dropping-commits-with-git-rebase.md )
176176- [ Dry Runs in Git] ( git/dry-runs-in-git.md )
177177- [ Excluding Files Locally] ( git/excluding-files-locally.md )
178+ - [ Find The Date That A File Was Added To The Repo] ( git/find-the-date-that-a-file-was-added-to-the-repo.md )
178179- [ Find The Initial Commit] ( git/find-the-initial-commit.md )
179180- [ Get The Short Version Of The Latest Commit] ( git/get-the-short-version-of-the-latest-commit.md )
180181- [ Grab A Single File From A Stash] ( git/grab-a-single-file-from-a-stash.md )
Original file line number Diff line number Diff line change 1+ # Find The Date That A File Was Added To The Repo
2+
3+ The ` git log ` command has a bunch of flags that you can use to filter
4+ commits and format their output.
5+
6+ We can get ` git log ` to only show the date for a commit in the ` short `
7+ format with the following flags:
8+
9+ ``` bash
10+ $ git log --pretty=format:" %ad" --date=short
11+ ```
12+
13+ We can also get ` git log ` to filter commits to just those that have files
14+ being added:
15+
16+ ``` bash
17+ $ git log --diff-filter=A
18+ ```
19+
20+ Like many ` git ` commands, we can restrict the output to those that match a
21+ path or file.
22+
23+ ``` bash
24+ $ git log -- README.md
25+ ```
26+
27+ If we put all of these together, then we have a one-line command for getting
28+ the date a specific file was added to the repository:
29+
30+ ``` bash
31+ $ git log --pretty=format:" %ad" --date=short --diff-filter=A -- README.md
32+ 2015-02-06
33+ ```
34+
35+ See ` man git-log ` for more details.
You can’t perform that action at this time.
0 commit comments