有关多个远程存储库的Git状态 [英] Git status in regards to multiple remote repositories

查看:126
本文介绍了有关多个远程存储库的Git状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



项目,我已经按照这些帖子中的答案,在那里我设置了git-push推送到多个仓库: 从多个远程位置拉/推



git同时推送到多个存储库


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

  repositoryformatversion = 0 
filemode = true
bare = false
logallrefupdates = true
[branchmaster]
remote =原产地
合并=参考/头/主
[远程原产地]
网址= https://www.example.com/g it / project /
url = git@github.com:username / project.git
[remoteexample]
url = https://www.example.com/git/project /
fetch = + refs / heads / *:refs / remotes / example / *
[remotegithub]
url = git@github.com:username / project.git
fetch = + refs / heads / *:refs / remotes / github / *

当涉及到做一个git推/拉。

使用我已经使用的脚本:

  git status --short 

但这只显示未提交的更改。 ..即使没有--short标志,它也不会显示通常只有1个遥控器显示的内容:

 您的分支在1次提交之前超过'origin / master'。 

尝试运行以下任何diff命令也似乎不起作用...它是第一次,但它似乎记住了它在设置时的日期/时间的远程文件,所以当你进行更多的修改时,它将它们与历史版本进行比较:

  git diff --name-statusorigin; 
git diff --name-statusorigin / master;
git diff --name-statusexample / master;
git diff --name-statusgithub / master;

有什么想法?我相当新的Git。

解决方案

我相信这个方法可能有点bug,因为它似乎记住一个提交参考对于每个远程,但在执行推/拉时不会更新...因此,当通过差异检查时,它总是会查看旧的提交ref以进行比较。



虽然它不是解决这个设置的方法,但我已经回到了一个单独的远程设置,但是编辑它以便它有两个urls ...所以虽然只能从一个远程发生,但是当我推动时,它有两个:

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

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


I have a script which emails me a reminder if I've forgotten to commit or push some code on each of my 40+ repositories.

With 2 of my projects, I have followed the answers in these posts, where I have set-up "git-push" to push to multiple repositories:

pull/push from multiple remote locations

git push to multiple repositories simultaneously

So I have a .git/config file with:

[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/*

This works well when it comes to doing a git push/pull.

With the script I have used:

git status --short

But this only shows un-commited changes... even without the "--short" flag, it does not show what normally appears with only 1 remote:

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

Trying to run any of the following "diff" commands also doesn't seem to work... well it does on the first time, but it seems to remember the remote files at the date/time when it was setup, so as you make more changes it compares them against that version in history:

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

Any thoughts? I am fairly new to Git.

解决方案

I believe this method is possibly a bit buggy, as it seems to remember a commit ref for each remote, but this does not get updated when doing a push/pull... so when checking via a diff, its always going to look at the old commit ref for a comparison.

While its not a solution to this setup, I have gone back to a single remote setup, but edited it so that it has 2 urls... so while the pull only happens from one remote, when I push, it goes to two:

[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

Note: This only works for now, as I'm the only committer.

这篇关于有关多个远程存储库的Git状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆