在gitlab中创建合并请求时,我经常收到一条消息:请求将branch-A合并到develop([x]后面提交)gitlab想要告诉我什么?我应该担心还是需要修理一些东西(什么)?
Jas*_*ker 10
如果您看到“behind by X commits”消息,则 gitlab 表明您要合并的分支已从您的分支点移开。
当您查看 gitlab 中的差异时,它们可能看起来令人困惑,可能表明您即将撤消在目标分支上的后续提交中实现的更改。
如果您想确保看到合并将执行的更改,最安全的做法是通过首先合并到目标分支来更新要合并的分支...
# fetch the latest code on all branches
git fetch
# checkout your working branch (if you're not already on it)
git checkout branch-A
# merge in the target branch
git merge origin/develop
Run Code Online (Sandbox Code Playgroud)
修复可能出现的任何冲突,然后提交它们:
# stage changes & commit
git add .
git commit
# push changes to origin
git push
Run Code Online (Sandbox Code Playgroud)
如果您现在刷新 gitlab 上的合并请求页面,“后面”消息将消失,差异将仅反映您所做的更改。
这比重新建立分支安全得多,因为它不需要推送--force。这也意味着 git 时间线的时间顺序与实际发生的情况相匹配,因此,如果您试图在未来追踪某个问题,您就不会被重写历史所误导。
缺点是提交历史记录可能看起来有点混乱。
在一段时间内,在项目中打开合并请求通常会导致您尝试合并的分支版本因其他人将其更改合并到其中而过时.
Gitlab通过显示您更新的分支版本在远程分支后面的数量来帮助您.
落后不会对合并行为造成任何阻碍,但是rebase在你合并的分支之上你的承诺是一种常见的做法.这将使您的合并请求更新,方法是按时间顺序将提交放在已经在该分支中的提交之后.这种方法使得负责合并的人的工作更容易,因为提交者本身已经解决了可能发生的任何冲突.
要执行rebase以下操作,您提出的方案将如下所示:
# Add a remote named `upstream` pointing to the original repository
git remote add upstream https://gitlab.example.com/example/your_project.git
# Fetch the latest commmits from `upstream`
git fetch upstream
# Checkout our branch-A
git checkout branch-A
# Rebase our branch on top of the `upstream/develop` branch
git rebase upstream/develop
# If needed fix any conflicts that may have appeared and then `git rebase --continue`
# Push the changes to the branch of your merge request
git push --force origin branch-A
Run Code Online (Sandbox Code Playgroud)
注意:推送时需要--force,因为您正在重写分支的提交历史记录.
| 归档时间: |
|
| 查看次数: |
6107 次 |
| 最近记录: |