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
Github pull request shows too many changes/commits
提问by Evan Hobbs
We have two branches: develop
and master
.
我们有两个分支:develop
和master
。
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 develop
into master
without a problem.
此外,它会说“不能自动合并”时,在命令行中,我能够合并develop
成master
没有问题。
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 develop
to master
. Only the most recent commit is new. The others were merged previously:
And the output of
git log --oneline --decorate --all --graph
编辑:当我们尝试合并develop
到master
. 只有最近的提交是新的。其他人先前已合并:
以及的输出
git log --oneline --decorate --all --graph
回答by Niemi
Your git log shows that there is a lot of commits in the develop
branch that don't exist in the master
branch. The pull request correctly shows a list of these commits, that can be merged into the master
branch.
您的 git 日志显示该develop
分支中有很多该分支中不存在的提交master
。拉取请求正确显示了这些提交的列表,可以合并到master
分支中。
To list all commits from the develop
branch that are not part of the master
branch 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 develop
has been merged into master
previously. But since these merge commits are no longer in the master
branch, 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 master
branch?
从您的 git 日志来看,它似乎develop
已合并到master
以前。但是由于这些合并提交不再在master
分支中,是否有人将主分支重置为早期状态?如果您部署到同步到master
分支的环境,可能会回滚更改?
Solution
解决方案
To get master
in sync with develop
again:
为了得到master
同步与develop
再次:
- Checkout
develop
andpull
to make sure the branch is up to date - Do the same thing with
master
- Merge
develop
intomaster
- Resolve the conflicts
- Push the
master
branch
- 结帐
develop
并pull
确保分支是最新的 - 做同样的事情
master
- 合并
develop
成master
- 解决冲突
- 推
master
分支
Now master
will be in sync with develop
again and the list of commits in develop
that master
is 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
试并提交的名单develop
是master
缺乏应该是空的。用 列出这些提交git log master..develop
。您的下一个拉取请求将仅包含您在此合并后所做的提交。
Further investigation
进一步的调查
If you want to investigate further how you ended up in this state you can use reflog
to see what changes that have been made to the master
branch. Fore example if one of the more recent commits in develop
previously has been part of the master
branch.
如果您想进一步调查您是如何结束这种状态的,您可以使用它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 development
branch so here is my try.
I am considering the problem that your development branch is not in sync with master
我不确定我的操作是否正确。据我了解,您在development
分支中有一次提交,所以这是我的尝试。我正在考虑你的开发分支与master不同步的问题
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
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
Now switch to master branch and update it with remote. git checkout master & git pull origin master
Switch to development branch and update it with remote. git checkout development & git pull origin development
merge the master to it. git merge master
At this point your development branch is in sync with master but locally
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.
Now take back your local changes that you stashed in step #2. git stash pop
Now commit it and push to the development branch and see the PR.
恢复开发分支提交,同时保留本地更改 git reset --soft HEAD^ # 假设最后一次提交是您的
此时,您的本地更改将按原样保留在您的计算机中
现在将其推送到 git .. 此时您可以尝试强制推送。您可以从这里获取帮助 回滚远程 Git 存储库
存储本地更改,以便您将来可以获取这些更改:git stash
此时您的开发分支是干净的并且没有本地更改
现在切换到 master 分支并使用远程更新它。git checkout master & git pull origin master
切换到开发分支并使用远程更新它。git checkout 开发 & git pull origin 开发
将主人合并到它。git合并大师
此时你的开发分支与 master 同步但在本地
将开发分支推送到远程服务器:git push origin developent
现在你可以去 github 并提出 PR,看看是否仍然显示差异。如果上述步骤没有问题,则不应显示任何此类差异。
现在收回您在第 2 步中隐藏的本地更改。git stash pop
现在提交并推送到开发分支并查看 PR。
If Everything works fine then it should show the correct diff. git clean
also might be helpful after step #2.
如果一切正常,那么它应该显示正确的差异。git clean
在第 2 步之后也可能会有所帮助。