Git合并并推送 [英] Git merge and push

查看:344
本文介绍了Git合并并推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Git,所以我觉得这个问题可能是一天中最新的问题,因为这个任务非常简单,但它导致了一个令人头疼的问题。



我有2个本地分行:


  • 主人

  • 本地/生产



  • 和2个遥控器:


    • master

    • 生产



    我需要将本地更改传递给生产。所以,我的工作流程是:

    pre $ g $ c $ git checkout local / production
    git merge master
    git commit
    git push

    git merge:
    似乎工作正常,它检测到所有的差异。



    git commit:


    关于分支本地/生产



    您的分支在2次提交之前领先于'origin / production'。

    没有提交(工作目录干净)


    git push:


    一切都是最新的


    无法将我的更改推送到远程存储库。

    解决方案

根本原因: ,在我看来,你的 local / production 没有跟踪 origin / production 。你可以用 git branch -avv 来检查。

关于 git push :请注意,不带参数的 git push 会更新所有已在本地更新的远程分支跟踪分支(从 git-push(1)手册页):

  git push ... [< repository> [< refspec> ...]] 

特殊refspec:(或+:允许非快进更新)将git指向
推送匹配分支:for each如果在远程
端已经存在一个同名的分支,则
远程端会被更新。如果没有找到明确的refspec(这是
既不在命令行中,也不在相应的远程
文件的任何Push行中 - 见下文),这是默认操作模式。

因为简单的 git push 的结果是如果忘记了在本地分支所做的更改,有时几乎没有意外,我个人喜欢明确指定要推送哪些分支。在你的情况下,这似乎是你想要做的:

  git push origin local / production:production 

如果您希望 local / production 跟踪 origin / production ,您可以为 origin / production 创建本地/生产跟踪分支>使用选项 -u

  git push -u origin local /生产:生产

(只需要一次)。然后你可以从原点拉到 local / production

摘要:您需要了解跟踪分支的概念以及 git push $ b

PS 我想知道您的分行名称 local / production 在这里。为什么不只是生产?我怀疑你已经有生产跟踪原产地/生产,也许使用 local / production 为你本地开发。在这种情况下,一个合理的工作流程就是这样的:


  1. git pull原产地生产:生产生产中有新的提交 生成

  2. $ c>,即 local / production 在后面,然后将 local / production 放在生产(或合并生产本地/生产

  3. 您想要推送您的更改的时刻, merge cherry-pick 您的提交到 production ,然后用 git push origin production:production 来推送更改。


I am starting with Git, so I feel that this question could be the newbiest question of day because this task is so simple, but it's causing a terrible headache..

I have 2 local branches:

  • master
  • local/production

And 2 remotes:

  • master
  • production

I need to pass local changes to production. So, my workflow was:

git checkout local/production
git merge master
git commit
git push

git merge: Seems Work fine, it detected all differences.

git commit:

On branch local/production

Your branch is ahead of 'origin/production' by 2 commits.

nothing to commit (working directory clean)

And git push:

Everything up-to-date

So that's all, I couldn't push my changes to remote repository.

解决方案

Root cause: To cut the explanation short, it appears to me that your local/production is not tracking origin/production. You can check this with git branch -avv.

About git push: Note that git push without arguments will update all the remote branches that have updated in your local tracking branches (from the git-push(1) manual page):

git push ...  [<repository> [<refspec>...]]

The special refspec : (or +: to allow non-fast-forward updates) directs git to
push "matching" branches: for every branch that exists on the local side, the
remote side is updated if a branch of the same name already exists on the remote
side. This is the default operation mode if no explicit refspec is found (that is
neither on the command line nor in any Push line of the corresponding remotes
file---see below).

Because the result of simple git push is sometimes little unexpected if forgotten what changes done in local branches, I personally like to explicitly specify which branches I want to push. In your case it seems this is what you want to do:

git push origin local/production:production

If you want local/production to track origin/production, you can make the local/production tracking branch for origin/production using option -u:

git push -u origin local/production:production

(only required once). Then you can pull from origin to local/production.

Executive Summary: you need to understand the concept of tracking branch and the peculiar semantics of git push.

P.S. I am wondering about your choice of your branch name local/production here. Why not just production? I am suspecting you already have production tracking origin/production and maybe use local/production for you local development. In this case a reasonable work flow is like this:

  1. git pull origin production:production to pull the changes to your production
  2. If there are new commits in production, that is local/production is behind then either rebase your local/production on production (or merge production on local/production)
  3. the moment you want to push your changes, merge or cherry-pick your commits to production and push the changes with git push origin production:production.

这篇关于Git合并并推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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