【发布时间】:2018-01-15 16:28:31
【问题描述】:
这个问题可能看起来很奇怪,但我在重写 100 多次提交后同步 git 历史记录时遇到了问题。
在我重写的机器上,一个简单的git fetch 同步了所有内容。
在另一台 mac 机器上,git sync 没有帮助,但是在随机删除本地 .git/ 日志和 refs 文件然后发出 git pull 后,历史记录得到了刷新。
但是,无论我在 Windows 机器上做什么,我都无法刷新项目历史记录。都试过了:
-
git reset --hard HEAD&git fetch git fetch --allgit pull- 等
每次在 Windows 机器上,我都会收到来自不同作者的相同提交的重复条目(我更改了作者字段)。
我使用本教程进行了大量的历史重写:
https://help.github.com/articles/changing-author-info/
Open Terminal.
Create a fresh, bare clone of your repository:
git clone --bare https://github.com/user/repo.git
cd repo.git
Copy and paste the script, replacing the following variables based on the information you gathered:
OLD_EMAIL
CORRECT_NAME
CORRECT_EMAIL
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
view rawgit-author-rewrite.sh hosted with ❤ by GitHub
Press Enter to run the script.
Review the new Git history for errors.
Push the corrected history to GitHub:
git push --force --tags origin 'refs/heads/*'
Clean up the temporary clone:
cd ..
rm -rf repo.git
有没有人经历过大规模的 git 历史重写?如果是,其他团队成员有哪些步骤来刷新他们的 git 历史记录?
【问题讨论】:
-
git reset --hard HEAD仅刷新您的 current 提交中的文件,如果这是在重写期间丢失的提交之一,这将无济于事。而是使用git reset --hard origin/branchname,替换为您所在的分支名称(如果需要,请替换为您的遥控器的名称)。另外,请确保您有本地存储库的备份,如果您丢失文件,我概不负责。 -
@LasseVågsætherKarlsen 我是否必须单独重置每个分支(或通过循环脚本)?没有像
fetch这样的 Git 命令来刷新所有分支的完整历史记录?