【问题标题】:How to check if specific local git branch is up-to-date with the remote version?如何检查特定的本地 git 分支是否与远程版本是最新的?
【发布时间】:2016-04-23 18:39:53
【问题描述】:

我知道有人问过很多与此类似的问题,但是我觉得很多答案都有很多模棱两可的地方。

我的情况:

1 个名为 Bicycle 的 repo,它有 2 个分支 master 和 staging。

假设我的本地仓库(主仓库和暂存仓库)与远程仓库是最新的。

然后,从事该项目的另一个人创建了一个名为 day-5 的分支并对项目进行了一些更改。

所说的人,一旦完成更改,就会推送他的更改,然后将第 5 天所做的更改与分支暂存合并,但不是主节点。

我的问题:

假设我不一定知道对分期进行了任何更改。对我来说,检查远程暂存版本是否发生了本地版本没有的更改的最简单方法是什么?

【问题讨论】:

  • 我认为,如果您要链接到您认为无用的其他问答,并描述它们无用的原因,这会有所帮助。无论如何,下面 CodeWizard 的回答似乎对您的设置是正确的。

标签: git branch git-branch


【解决方案1】:

对我来说,检查远程暂存版本是否发生了本地版本没有的更改的最简单方法是什么?

首先你可以执行一次提取

# update the local repository (no the branch just the repository)
git fetch --all --prune

# compare the local branch to the remote branch
git diff <branch> <origin/branch>

# if you are on the current branch you can drop the first part 
# git will use the current branch as the left branch
git diff <origin/branch>

很少有其他命令或多或少会做同样的事情

git log <branch> ^<origin/branch>
git log ^<branch> <origin/branch>

它将记录拉/推中的差异

【讨论】:

    【解决方案2】:

    你应该这样做

    git checkout staging
    

    然后切换到那个分支

    git status
    

    应该告诉你,如果你是最新的远程或者你的分支是否可以快进。

    【讨论】:

      【解决方案3】:

      如果您在本地分支中并且需要使用远程中的任何分支进行更新,您可以随时尝试

      git pull origin <remote_branch_name>
      

      如果您希望使用暂存分支更新本地分支

      git pull origin staging
      

      【讨论】:

        猜你喜欢
        • 2022-01-05
        • 2011-12-17
        • 1970-01-01
        • 2013-03-11
        • 2018-05-29
        • 2018-09-12
        • 2010-12-20
        • 2013-07-07
        • 1970-01-01
        相关资源
        最近更新 更多