Stu*_*ser 15 windows-7 bash git-bash
我在 Windows7 上运行 git 的 bash 来管理项目的源代码控制。
我可以编辑C:\Program Files (x86)\Git\etc\git-prompt.sh
以使我在运行命令时使用时间戳吗?
例如代替
user.name@machine /c/somedirectory
$ git pull origin develop
remote: Counting objects: 1, done.
Run Code Online (Sandbox Code Playgroud)
显示
user.name@machine /c/somedirectory
$ git pull origin develop
21/04/2016 20:15:33
remote: Counting objects: 1, done.
Run Code Online (Sandbox Code Playgroud)
所以我可以知道在特定时间之前/之后是否运行了某些东西。
小智 14
这是您问题的解决方案,与您所写的唯一不同的是,时间戳显示在命令输出之后,而不是之前。
在 Windows Program Files 文件夹下,打开Git\etc\profile
或Git\etc\profile.d\git-prompt.sh
,搜索如下所示的行:
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 $
Run Code Online (Sandbox Code Playgroud)
并添加行
PS1="$PS1"' \t' # time
Run Code Online (Sandbox Code Playgroud)
在倒数第二行之前。这会给你提示:
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
$
Run Code Online (Sandbox Code Playgroud)
以下是您可以添加的其他有用选项的列表:http : //makandracards.com/makandra/1090-customize-your-bash-prompt
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 $
Run Code Online (Sandbox Code Playgroud)
\D{格式}
Run Code Online (Sandbox Code Playgroud)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
参考
https://bneijt.nl/blog/post/add-a-timestamp-to-your-bash-prompt/