gpt4 book ai didi

关于多个远程存储库的 Git 状态

转载 作者:太空狗 更新时间:2023-10-29 14:24:25 26 4
gpt4 key购买 nike

我有一个脚本,如果我忘记在我的 40 多个存储库中的每一个存储库上提交或推送一些代码,它会通过电子邮件提醒我。

在我的两个项目中,我遵循了这些帖子中的答案,在那里我设置了“git-push”以推送到多个存储库:

pull/push from multiple remote locations

git push to multiple repositories simultaneously

所以我有一个 .git/config 文件:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
url = https://www.example.com/git/project/
url = git@github.com:username/project.git
[remote "example"]
url = https://www.example.com/git/project/
fetch = +refs/heads/*:refs/remotes/example/*
[remote "github"]
url = git@github.com:username/project.git
fetch = +refs/heads/*:refs/remotes/github/*

这在执行 git 推/pull 时效果很好。

配合我用过的脚本:

git status --short

但这只显示未提交的更改......即使没有“--short”标志,它也不会显示通常只有 1 个 Remote 时出现的内容:

Your branch is ahead of 'origin/master' by 1 commit.

尝试运行以下任何“diff”命令似乎也不起作用......第一次时确实如此,但它似乎记得设置时的日期/时间的远程文件,因此,当您进行更多更改时,它会将它们与历史版本进行比较:

git diff --name-status "origin";
git diff --name-status "origin/master";
git diff --name-status "example/master";
git diff --name-status "github/master";

有什么想法吗?我是 Git 的新手。

最佳答案

我相信这个方法可能有点问题,因为它似乎记得每个远程的提交引用,但是在执行推/pull 时它不会更新......所以当通过差异检查时,它总是会查看旧的提交引用以进行比较。

虽然它不是此设置的解决方案,但我已经返回到单个远程设置,但对其进行了编辑,使其具有 2 个 url...到两个:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://www.example.com/git/project/
url = git@github.com:username/project.git

注意:这只适用于现在,因为我是唯一的提交者。

关于关于多个远程存储库的 Git 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11684637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com