mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Find The Date That A File Was Added To The Repo as a git til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||
|
||||
_744 TILs and counting..._
|
||||
_745 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -175,6 +175,7 @@ _744 TILs and counting..._
|
||||
- [Dropping Commits With Git Rebase](git/dropping-commits-with-git-rebase.md)
|
||||
- [Dry Runs in Git](git/dry-runs-in-git.md)
|
||||
- [Excluding Files Locally](git/excluding-files-locally.md)
|
||||
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
||||
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
||||
- [Get The Short Version Of The Latest Commit](git/get-the-short-version-of-the-latest-commit.md)
|
||||
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
|
||||
|
||||
35
git/find-the-date-that-a-file-was-added-to-the-repo.md
Normal file
35
git/find-the-date-that-a-file-was-added-to-the-repo.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Find The Date That A File Was Added To The Repo
|
||||
|
||||
The `git log` command has a bunch of flags that you can use to filter
|
||||
commits and format their output.
|
||||
|
||||
We can get `git log` to only show the date for a commit in the `short`
|
||||
format with the following flags:
|
||||
|
||||
```bash
|
||||
$ git log --pretty=format:"%ad" --date=short
|
||||
```
|
||||
|
||||
We can also get `git log` to filter commits to just those that have files
|
||||
being added:
|
||||
|
||||
```bash
|
||||
$ git log --diff-filter=A
|
||||
```
|
||||
|
||||
Like many `git` commands, we can restrict the output to those that match a
|
||||
path or file.
|
||||
|
||||
```bash
|
||||
$ git log -- README.md
|
||||
```
|
||||
|
||||
If we put all of these together, then we have a one-line command for getting
|
||||
the date a specific file was added to the repository:
|
||||
|
||||
```bash
|
||||
$ git log --pretty=format:"%ad" --date=short --diff-filter=A -- README.md
|
||||
2015-02-06
|
||||
```
|
||||
|
||||
See `man git-log` for more details.
|
||||
Reference in New Issue
Block a user