在 git bash 提交消息中使用日期
using date in git bash commit message
我在 windows 10 中使用 .bat
文件将更改推送到外部存储库,我有以下代码
#!/bin/bash
cd C:\path\to\my\repo
set timestamp=$(date +"%D %T")
git add .
git commit -m "Backup at: `%timestamp%`"
git push origin master
git pull origin master
我想要做的是让提交消息成为 "Backup at: date"
但它只是使 "Backup at: `$(date +T)\`"
有什么办法可以解决这个问题,让它成为日期吗?
您可以将脚本编写为常规 bash shell 脚本,因为 Windows 使用 Git Bash 执行 .sh
个文件。
所以这样写:
示例: myBackup.sh
#!/bin/bash
cd /c/path/to/repo
timestamp=$(date +%c)
git add .
git commit -m "Backup at: $timestamp"
git push origin master
echo Press Enter...
read
$(date +%c)
将为您提供语言环境日期和时间(例如,2020 年 3 月 15 日星期日 12:01:53 上午)使用 date --help
查看完整选项。不需要 set
使用像 $timestamp
而不是 %timestamp%
这样的变量并且没有反引号 (``
)
使用正斜杠 /
而不是反斜杠 \
反斜杠适用于 Windows.
我在 windows 10 中使用 .bat
文件将更改推送到外部存储库,我有以下代码
#!/bin/bash
cd C:\path\to\my\repo
set timestamp=$(date +"%D %T")
git add .
git commit -m "Backup at: `%timestamp%`"
git push origin master
git pull origin master
我想要做的是让提交消息成为 "Backup at: date"
但它只是使 "Backup at: `$(date +T)\`"
有什么办法可以解决这个问题,让它成为日期吗?
您可以将脚本编写为常规 bash shell 脚本,因为 Windows 使用 Git Bash 执行 .sh
个文件。
所以这样写:
示例: myBackup.sh
#!/bin/bash
cd /c/path/to/repo
timestamp=$(date +%c)
git add .
git commit -m "Backup at: $timestamp"
git push origin master
echo Press Enter...
read
$(date +%c)
将为您提供语言环境日期和时间(例如,2020 年 3 月 15 日星期日 12:01:53 上午)使用date --help
查看完整选项。不需要set
使用像
$timestamp
而不是%timestamp%
这样的变量并且没有反引号 (``
)使用正斜杠反斜杠适用于 Windows./
而不是反斜杠\