git Github 拉取请求显示太多更改/提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39048673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:12:17  来源:igfitidea点击:

Github pull request shows too many changes/commits

gitgithubversion-controlpull-request

提问by Evan Hobbs

We have two branches: developand master.

我们有两个分支:developmaster

For some reason when I create a PR of develop--> master. It shows a whole list of previous commits and changes even if I've made only a single line change in develop.

出于某种原因,当我创建develop-->的 PR 时master。它显示了以前提交和更改的完整列表,即使我在develop.

Also, it will say "Can't automatically merge" when from the command line I'm able to merge developinto masterwithout a problem.

此外,它会说“不能自动合并”时,在命令行中,我能够合并developmaster没有问题。

Any idea what might be going on? Previously it was working fine for us.

知道会发生什么吗?以前它对我们来说工作正常。

EDIT: Here's what it looks like when we try to merge developto master. Only the most recent commit is new. The others were merged previously: enter image description hereAnd the output of git log --oneline --decorate --all --graphenter image description here

编辑:当我们尝试合并developmaster. 只有最近的提交是新的。其他人先前已合并: 在此处输入图片说明以及的输出git log --oneline --decorate --all --graph在此处输入图片说明

回答by Niemi

Your git log shows that there is a lot of commits in the developbranch that don't exist in the masterbranch. The pull request correctly shows a list of these commits, that can be merged into the masterbranch.

您的 git 日志显示该develop分支中有很多该分支中不存在的提交master。拉取请求正确显示了这些提交的列表,可以合并到master分支中。

To list all commits from the developbranch that are not part of the masterbranch you can use the command git log master..develop. This should match the list you see in the pull request.

要列出来自该develop分支但不属于该master分支的所有提交,您可以使用该命令git log master..develop。这应该与您在拉取请求中看到的列表相匹配。

From your git log it looks like develophas been merged into masterpreviously. But since these merge commits are no longer in the masterbranch, is it possible that someone have done a reset of the master branch to an eariler state? Possibly to roll back changes if you have a deployment to an environment synced to the masterbranch?

从您的 git 日志来看,它似乎develop已合并到master以前。但是由于这些合并提交不再在master分支中,是否有人将主分支重置为早期状态?如果您部署到同步到master分支的环境,可能会回滚更改?

Solution

解决方案

To get masterin sync with developagain:

为了得到master同步与develop再次:

  1. Checkout developand pullto make sure the branch is up to date
  2. Do the same thing with master
  3. Merge developinto master
  4. Resolve the conflicts
  5. Push the masterbranch
  1. 结帐developpull确保分支是最新的
  2. 做同样的事情 master
  3. 合并developmaster
  4. 解决冲突
  5. master分支

Now masterwill be in sync with developagain and the list of commits in developthat masteris lacking should be empty. List these commits with git log master..develop. Your next pull request will only contain the commits you do after this merge.

现在,master将在同步与develop试并提交的名单developmaster缺乏应该是空的。用 列出这些提交git log master..develop。您的下一个拉取请求将仅包含您在此合并后所做的提交。

Further investigation

进一步的调查

If you want to investigate further how you ended up in this state you can use reflogto see what changes that have been made to the masterbranch. Fore example if one of the more recent commits in developpreviously has been part of the masterbranch.

如果您想进一步调查您是如何结束这种状态的,您可以使用它reflog来查看对master分支进行了哪些更改。例如,如果develop以前较新的提交之一是master分支的一部分。

git reflog master

If you wan to do this you can do it before you merge the branches so you can see how the history looked before the fix.

如果你想这样做,你可以在合并分支之前这样做,这样你就可以看到修复前的历史记录。

回答by MaNKuR

I am not sure if I got the op correctly. As I understood you have a single commit in the developmentbranch so here is my try. I am considering the problem that your development branch is not in sync with master

我不确定我的操作是否正确。据我了解,您在development分支中有一次提交,所以这是我的尝试。我正在考虑你的开发分支与master不同步的问题

  1. revert back the development branch commit while keeping the local changes git reset --soft HEAD^ # Assuming the last commit is yours

    At this point your local changes will stay in your machine as-is

    Now push this to git .. you may try force push at this point. You can take help from here Rolling back a remote Git repository

  2. Stash the local changes so that you can get these changes in future: git stash

    At this point your development branch is clean and has no local changes

  3. Now switch to master branch and update it with remote. git checkout master & git pull origin master

  4. Switch to development branch and update it with remote. git checkout development & git pull origin development

  5. merge the master to it. git merge master

    At this point your development branch is in sync with master but locally

  6. Push the development branch to remote server: git push origin developent

    Now you can go to the github and raise PR and see if still shows difference. It should not show any such difference if above steps works with no problem.

  7. Now take back your local changes that you stashed in step #2. git stash pop

  8. Now commit it and push to the development branch and see the PR.

  1. 恢复开发分支提交,同时保留本地更改 git reset --soft HEAD^ # 假设最后一次提交是您的

    此时,您的本地更改将按原样保留在您的计算机中

    现在将其推送到 git .. 此时您可以尝试强制推送。您可以从这里获取帮助 回滚远程 Git 存储库

  2. 存储本地更改,以便您将来可以获取这些更改:git stash

    此时您的开发分支是干净的并且没有本地更改

  3. 现在切换到 master 分支并使用远程更新它。git checkout master & git pull origin master

  4. 切换到开发分支并使用远程更新它。git checkout 开发 & git pull origin 开发

  5. 将主人合并到它。git合并大师

    此时你的开发分支与 master 同步但在本地

  6. 将开发分支推送到远程服务器:git push origin developent

    现在你可以去 github 并提出 PR,看看是否仍然显示差异。如果上述步骤没有问题,则不应显示任何此类差异。

  7. 现在收回您在第 2 步中隐藏的本地更改。git stash pop

  8. 现在提交并推送到开发分支并查看 PR。

If Everything works fine then it should show the correct diff. git cleanalso might be helpful after step #2.

如果一切正常,那么它应该显示正确的差异。git clean在第 2 步之后也可能会有所帮助。