How can I configure git bash to display a timestamp for each command?
Solution 1
This is solution to your problem, only difference from what you wrote, is that timestamp is displayed after the command output, and not before.
Under the Windows Program Files folder, open Git\etc\profile
or Git\etc\profile.d\git-prompt.sh
, search for lines which look like:
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change color
PS1="$PS1"'\u@\h ' # user@host<space>
PS1="$PS1"'\[\033[33m\]' # change color
PS1="$PS1"'\w' # current working directory
if test -z "$WINELOADERNOEXEC"
then
PS1="$PS1"'$(__git_ps1)' # bash function
fi
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
And add line
PS1="$PS1"' \t' # time
before second-to-last line. That will give you prompt like:
user.name@machine /c/somedirectory 18:34:35
$ git pull origin develop
remote: Counting objects: 1, done.
user.name@machine /c/somedirectory 18:42:12
$
Here is list of other useful options you can add: http://makandracards.com/makandra/1090-customize-your-bash-prompt
Solution 2
Win10 git-bash: C:\Program Files\Git\etc\profile.d
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"' \D{%F %T}' # time in ISO8601 format ←
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
\D{format}
the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
References
https://stackoverflow.com/questions/13001902/how-to-configure-git-bash-prompt-by-adding-datetime
https://bneijt.nl/blog/post/add-a-timestamp-to-your-bash-prompt/
Related videos on Youtube
StuperUser
A full stack web app developer most recently using Angular, WebAPI, Dapper. 1.5 years experience in QA and an ISTQB/ISEB Foundation Certificate in Software Testing. BA in Philosophy and Computing from University of Kent. #SOreadytohelp
Updated on September 18, 2022Comments
-
StuperUser over 1 year
I run git's bash on Windows7 to manage source control for projects.
Can I edit
C:\Program Files (x86)\Git\etc\git-prompt.sh
to enable me to timestamp when I ran commands?e.g. instead of
user.name@machine /c/somedirectory $ git pull origin develop remote: Counting objects: 1, done.
Displaying
user.name@machine /c/somedirectory $ git pull origin develop 21/04/2016 20:15:33 remote: Counting objects: 1, done.
So I can know whether something was run before/after a particular time.
-
Raymond over 2 yearsadd
alias git='date && git'
to your~/.bashrc
-
-
Sun almost 8 yearsI guess if you press enter to create a blank prompt before you execute the script, that might give you a start time. The end time would be the next prompt that appears after process executes and ends.
-
Shiyaz over 6 yearsI've used a slight variation so that the time stamp remains on a separate line instead of cluttering the bash command line.
PS1='[\t]'"$PS1" # time