GitHub 将推送时间永久存储在其数据库中
例如,您推送的时间可以在 GitHub Events API 上永久查看。
例如,https://api.github.com/repos/cirosantilli/china-dictatorship/events https://api.github.com/repos/cirosantilli/china-dictatorship/events现在包含实际推送数据“2020-12-29T11:37:26Z”:
"message": "66d9be0cb84c9650d6181b4b0fc2b70e2178bd9e",
"distinct": true,
"url": "https://api.github.com/repos/cirosantilli/china-dictatorship/commits/0817ad58873c5656d2828613a5a24ca8f286e910"
}
]
},
"public": true,
"created_at": "2020-12-29T11:37:26Z"
},
虽然实际提交 https://github.com/cirosantilli/china-dictatorship/commit/66d9be0cb84c9650d6181b4b0fc2b70e2178bd9e是“2020 年 12 月 29 日星期二 00:00:00 +0000”。
这个API数据直接存储在他们的数据库中,而不是在Git提交数据中,并且没有办法伪造它。
如果你想隐藏这一点,据我所知,没有其他选择,你必须:
- 在不同的时间推动,例如与 cron 作业
- 删除存储库,然后推送数据就会从 API 中消失
这是一个隐私问题,尽管坚定的攻击者当然能够通过轮询某些感兴趣的用户的个人资料来获得类似的结果。相关门票:
- https://github.com/isaacs/github/issues/142 https://github.com/isaacs/github/issues/142
提交数据时间
提交数据的提交时间可以通过环境变量控制:
GIT_COMMITTER_DATE=2000-01-01T00:00:00+0000 \
GIT_AUTHOR_DATE=2000-01-01T00:00:00+0000 \
git commit -m 'my message'
For --amend
,那里使用--date
作者日期选项:如何更改 Git 中旧提交的时间戳? https://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git/9701130#9701130
有提交消息对象上没有进一步的时间指示 https://stackoverflow.com/questions/22968856/what-is-the-file-format-of-a-git-commit-object/37438460#37438460,这样对于隐私来说就足够了。
您可能希望自动执行此操作post-commit
钩子解释如下:可以在 git hook 内自定义 GIT_COMMITTER_DATE 吗? https://stackoverflow.com/questions/32699631/can-git-committer-date-be-customized-inside-a-git-hook/53514970#53514970
这是一个更高级的钩子,使您的提交将在每天的午夜开始,并且每次新提交增加一秒 https://askubuntu.com/questions/408775/add-seconds-to-a-given-date-in-bash。这使得提交按时间排序,同时仍然隐藏提交时间。
.git/hooks/提交后
#!/usr/bin/env bash
set -eu
echo post-rewrite
if [ ! "${CIROSANTILLI_GITHOOKS_DISABLE:-0}" = 1 ]; then
declare -a olds
declare -A oldnew
while IFS= read -r line; do
echo "$line"
old="$(echo "$line" | cut -d ' ' -f1)"
new="$(echo "$line" | cut -d ' ' -f2)"
oldnew[$old]="$new"
olds+=("$old")
news+=("$new")
done
# Save unstaged changes. Otherwise e.g. git commit --amend destroys them!
# https://stackoverflow.com/questions/24520791/check-if-git-stash-stashed-anything/38785582#38785582
nstash="$(git stash list | wc -l)"
git stash
git reset --hard "${news[0]}~"
for old in "${olds[@]}"; do
new="${oldnew[$old]}"
git cherry-pick "$new" &>/dev/null
olddate="$(git log --format='%cd' -n 1 "$old")"
CIROSANTILLI_GITHOOKS_DISABLE=1 \
GIT_COMMITTER_DATE="$olddate" \
git commit \
--amend \
--no-edit \
--no-verify \
&>/dev/null \
;
done
# Restore unstaged changes.
if [ "$(git stash list | wc -l)" -ne "$nstash" ]; then
git stash apply
fi
echo
fi
GitHub 上游 https://github.com/cirosantilli/dotfiles/blob/0406773ce990a48445edae8863daf98af988d6d5/home/.git_hooks/post-commit.
不要忘记:
chmod +x .git/hooks/post-commit
在 git 2.19、Ubuntu 18.04 上测试。
不要忘记还处理:
-
git rebase
with a post-rewrite
hook: git rebase 而不改变提交时间戳 https://stackoverflow.com/questions/2973996/git-rebase-without-changing-commit-timestamps/53516609#53516609
-
git am
with --committer-date-is-author-date
正如所解释的可以在 git hook 内自定义 GIT_COMMITTER_DATE 吗? https://stackoverflow.com/questions/32699631/can-git-committer-date-be-customized-inside-a-git-hook/53514970#53514970
否则提交者日期仍然会泄露。
批量历史修改
以下是一种将现有范围内所有提交的提交时间固定为午夜同时保持日期不变的方法:
git-hide-time() (
first_commit="$1"
last_commit="${2:-HEAD}"
git filter-branch --env-filter '
d="$(echo "$GIT_COMMITTER_DATE" | sed "s/T.*//")T00:00:00+0000)"
export GIT_COMMITTER_DATE="$d"
export GIT_AUTHOR_DATE="$d"
' --force "${first_commit}~..${last_commit}"
)
也可以看看:如何更改 Git 中旧提交的时间戳? https://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git