Using Git to Figure out How Long a Line of Text Has Been In a File -
suppose have file1.txt
in git repository. suppose file has line of text: an old line of text
.
is there way figure out, through git (or other unix utility?) how many days line of text has been in file?
you can use
datefrom=$(git log --pretty=format:'%cd' --date=format:'%y-%m-%d' -s 'line find' -- file1.txt)
that result in date of commit introduced string.
- log searches commit history
- -s option finds first introduction of string
- --pretty=format:'%ad' prints committer date
- --date=format formats date
now this: https://unix.stackexchange.com/questions/215934/whats-a-smart-way-to-count-the-number-of-days-since-x get:
echo $(( (`date +%s` - `date +%s -d $(datefrom)`) / 86400 ))
which results in number of days introducing commit.
ofcourse can put in 1 command , make alias, or can create git-command-name script , put user/bin folder , git recognize git command can invoke
git command-name 'line find'
Comments
Post a Comment