首页 > 解决方案 > GitHub 上的拉取请求包含我同事的其他提交

问题描述

我正在与一个团队合作,我们正在使用 GitHub。

假设我设置了两个远程存储库,如下所示:

所有这些存储库都有用于开发的分支“develop” 。我在本地分支“开发”上工作,稍后将被推送到起源/开发。

以下是我在创建拉取请求之前发出的命令。请注意,我当时签出了本地“开发”

$git commit

$git pull --rebase=preserve upstream develop

$git push
To https://github.com/lamhohs/some_repo.git
 ! [rejected]            develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://github.com/lamhohs/some_repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

$ git pull --rebase=preserve origin develop

$ git push

上一次推送命令成功。然后我创建了一个从origin/developupstream/develop的拉取请求。但是,在 GitHub 中,拉取请求显示了我同事的其他提交。这使审阅者几乎无法审查我所做的更改。

我的问题是:如何创建更清晰的拉取请求?


我的解决方案是,'git pull --rebase=preserve upstream develop'我没有调用,而是调用'git pull'如下:

$ git pull upstream develop
$ git push

尽管如此,拉取请求还包含从upstream/develop到本地'develop'的合并提交。

标签: gitgithubgit-rebase

解决方案


2 解决方案:

  1. 由 SHA 执行代码审查。无论您使用什么系统,都必须为您的代码审查支持某种 SHA 选择。类型:

    gitk&
    

    找到提交的 SHA。将这些 SHA 上传到您的代码审查中,它将仅显示来自这些提交的更改。

  2. 确保您的更改是最后一次更改。这些是将所有提交转换为 1 个提交的一些步骤,这是您分支上的最新提交。

    git branch -m "mydevelop"
    
    git pull
    
    git checkout develop
    
    git merge --squash mydevelop develop
    
    git commit -m "my changes as one commit"
    

    正如 choroba 所说,您不应该在工作中使用同名的开发分支。你应该拉它,重命名它,在重命名的分支上做你的工作,然后当你准备好与开发合并时,即当你将它合并回开发时。如果您继续直接对开发分支进行更改,那么如果您对 git 没有很好的理解,那么您将来会遇到更多麻烦。


推荐阅读