Git合并并推送 [英] Git merge and push
问题描述
我开始使用Git,所以我觉得这个问题可能是一天中最新的问题,因为这个任务非常简单,但它导致了一个令人头疼的问题。
我有2个本地分行: 和2个遥控器: 我需要将本地更改传递给生产。所以,我的工作流程是: git merge: git commit: 关于分支本地/生产 您的分支在2次提交之前领先于'origin / production'。 没有提交(工作目录干净) 和 git push: 一切都是最新的 无法将我的更改推送到远程存储库。
pre $ g $ c $ git checkout local / production
git merge master
git commit
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
。
摘要:您需要了解跟踪分支的概念以及 PS 我想知道您的分行名称 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: And 2 remotes: I need to pass local changes to production. So, my workflow was: 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 About Because the result of simple If you want (only required once). Then you can pull from origin to Executive Summary: you need to understand the concept of tracking branch and the peculiar semantics of P.S. I am wondering about your choice of your branch name
这篇关于Git合并并推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git push $的特殊语义c $ c $。
$ b local / production
在这里。为什么不只是生产
?我怀疑你已经有生产
跟踪原产地/生产
,也许使用 local / production
为你本地开发。在这种情况下,一个合理的工作流程就是这样的:
git pull原产地生产:生产$ c $如果在
生产中有新的提交$ c>
local / production
在后面,然后将 local / production
放在生产
(或合并生产
于本地/生产
)
merge
或 cherry-pick
您的提交到 production
,然后用 git push origin production:production
来推送更改。
git checkout local/production
git merge master
git commit
git push
local/production
is not tracking origin/production
. You can check this with git branch -avv
.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).
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
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
local/production
. git push
.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:
git pull origin production:production
to pull the changes to your production
production
, that is local/production
is behind then either rebase your local/production
on production
(or merge production
on local/production
)merge
or cherry-pick
your commits to production
and push the changes with git push origin production:production
.