Git合并推

Mar*_* B. 16 git branch push github

我是从Git开始的,所以我觉得这个问题可能是一天中最新的问题,因为这个任务很简单,但它引起了一个非常头疼的问题.

我有2个本地分支机构:

  • 本地/生产

和2遥控器:

  • 生产

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

git checkout local/production
git merge master
git commit
git push
Run Code Online (Sandbox Code Playgroud)

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

git commit:

在分支本地/生产

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

无需提交(工作目录清理)

git推:

一切都是最新的

这就是全部,我无法将我的更改推送到远程存储库.

Foo*_*ooF 16

根本原因:为了缩短解释,在我看来你local/production没有跟踪origin/production.你可以用它来检查git branch -avv.

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

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).
Run Code Online (Sandbox Code Playgroud)

因为git push如果忘记在本地分支中做了哪些更改,简单的结果有时很少会出乎意料,我个人想明确指定我想要推送哪些分支.在你的情况下,这似乎是你想要做的:

git push origin local/production:production
Run Code Online (Sandbox Code Playgroud)

如果要local/production跟踪origin/production,可以使local/production跟踪分支origin/production使用选项-u:

git push -u origin local/production:production
Run Code Online (Sandbox Code Playgroud)

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

执行摘要:您需要了解跟踪分支的概念和特殊的语义git push.

PS我想知道你local/production在这里选择你的分行名称.为什么不production呢?我怀疑你已经production跟踪origin/production并可能local/production用于本地开发.在这种情况下,合理的工作流程是这样的:

  1. git pull origin production:production 把改变拉到你的 production
  2. 如果有新的提交production,即local/production是背后则要么衍合local/productionproduction(或合并productionlocal/production)
  3. 您想要推送更改,merge或者cherry-pick您的提交production并推送更改的那一刻git push origin production:production.