如何在拉/合并请求之前更新(拉)分支? [英] How to update(pull) a branch before a pull/merge request?

查看:63
本文介绍了如何在拉/合并请求之前更新(拉)分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,假设我有一个名为 develop 的分支,并且我所有的功能都是从 develop 创建的分支,稍后我将需要执行合并请求(在GitLab中,在GitHub中将是请求请求).

For instance, let's suppose I have a branch called develop, and all my features will be a branch created from develop that later I will need to do a merge request (in GitLab, what in GitHub would be a pull request).

如果我需要在将新分支推送到 origin 并进行合并/拉取请求之前更新我的新分支,请执行" git pull origin development ".也会更新我的新分支吗?
如果没有,我该怎么办?

If I need to update my new branch before push it into origin and do a merge/pull request, does "git pull origin develop" would update my new branch too?
If not, how can I do this?

推荐答案

有几种方法,这取决于您使用的分支策略.在逐个项目的基础上,我会选择一种策略并坚持下去,但是最有效的策略取决于您要寻找的内容.

There are a few methodologies, and it depends on the branching strategy that you are using. On a project-by-project basis, I would pick one strategy and stick with it, but the one that works best depends on what you are looking for.

合并:(从分支机构执行):

Merge: (execute from the branch):

  • git pull(或git fetch)
  • git merge origin/develop
  • git push

这将保留历史记录,并且是非破坏性的.它在分支上创建一个新的提交,表示将开发带入分支的更改.

This preserves history and is non destructive. It creates a single new commit on the branch representing the change(s) from develop being brought into the branch.

变基:(从分支机构执行):

Rebase: (execute from the branch):

  • git pull --rebase(或git fetch)
  • git rebase origin/develop
  • git push --force(或git push -f)

此REWRITES历史记录,具有破坏性.分支上的原始提交将被丢弃并重新创建(它们看起来类似(注释,文件和作者身份相同),但是具有不同的提交ID和提交时间,这使历史更加线性".

This REWRITES history and is destructive. The original commits on the branch are discarded and recreated (they will look similar (same comment, file and authorship), but will have different commit-ids and commit-time. It makes history more 'linear'.

用南瓜重新调味:(从分支机构执行):

Rebase with squash: (execute from the branch):

  • git pull(或git fetch)
  • git rebase origin/develop
  • git rebase -i HEAD〜2(假设分支比开发提前2次提交)
  • git push --force(或git push -f)

类似于变基(上文)-重写和破坏性-但将分支折叠为单个提交.历史不仅是线性的,而且也很简洁-整个分支都折叠成一个提交.

Similar to rebase (above) - rewrites and destructive - but collapses the branch down to a single commit. History is not only linear, it is also concise - entire branches are collapsed to a single commit.

我通常的建议是避免对经验不​​足的团队使用rebase.重新设置很容易遇到麻烦,并且有很多事情要当心.不过,重新建立基础可以保留相当长的历史记录(如果那很重要)-但是取证工作会变得更加困难(如果那很重要).-力"表示是git告诉您要取消安全措施并要小心操作的一种方法.

My usual advice is to avoid using rebase with inexperienced teams. It's easy to get into trouble with rebase and there are all sorts of things to be wary of. Nevertheless, rebase makes for pretty history (if that's important) - but forensics is made harder (if that's important). The "--force" is git's way of telling you that you are taking the safeties off and to be careful what you are doing.

查看git-pull上的手册页.有一些命令可以折叠拉/合并或拉/变基,以将步数减少一.还有git-config命令可以指定拉"始终是拉并"或拉并变基".

Check out the man page on git-pull. There are commands to collapse pull/merge or pull/rebase to reduce the steps by one. There are also git-config commands to specify that a 'pull' is always a 'pull-and-merge' or 'pull-and-rebase'.

这篇关于如何在拉/合并请求之前更新(拉)分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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