Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add time on git command prompt

I want to add current time on git command prompt. with keeping the same actual parameters.

How to do it like the following image.

enter image description here

like image 389
walidtlili Avatar asked Jun 23 '19 11:06

walidtlili


People also ask

Can I use git commands in cmd?

All you have to do is load Command Prompt (Load the Start menu, then click "Run", type cmd and hit enter), then you can use Git commands as normal.

What does git add period do?

The period in git add . means the current directory and all files within it, recursively. (The asterisk in git add * , on the other hand, would mean all files in the current directory except ones that begin with a period.)

How add to git commit?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

Where do I type git commands?

Press 'Start' button in Windows, type 'cmd' in the search field on the bottom of menu. There you have the command line console. Try to type git --version , if show something like 'git version 1.8. 0.2', you're ready to input all the commands here.


1 Answers

Navigate to your Git installation folder to where your profiles are located: Git\etc\profile.d and open the file called git-prompt.sh. Change the last block of code to include the time stamp like this:

PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"' \A \D{%d/%m/%Y}'   # time & date
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

Just to highlight, this is the line you are inserting just before bash inserts a new line:

PS1="$PS1"' \A \D{%d/%m/%Y}'   # time & date

\A will display the current time in 24-hour HH:MM format and \D{format} will display the date with a custom format. The format takes any arguments supported by strftime(3). The format we have used is broken down into these segments:

%m - The month as a decimal number (range 01 to 12). 
%d - The day of the month as a decimal number (range 01 to 31). 
%y - The year as a decimal number without a century (range 00 to 99).

That should give you a following console output similar to this:

~/Desktop/Code/carhabti (master) 01:28 23/06/2019

Here is a list of escape sequences that are used to format time in bash:

\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
like image 171
Matthew Avatar answered Oct 31 '22 22:10

Matthew