推送到远程时如何避免来自Git pull的合并提交 [英] How to avoid merge commits from Git pull when pushing to remote
本文介绍了推送到远程时如何避免来自Git pull的合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个存储库和一些本地更改要提交. 在提交之前,我使用Eclipse中的Egit将更改拉到本地.
I have a repository and some local changes to commit. Before committing, I pulled the changes onto my local using Egit in Eclipse.
它将创建一个合并提交,而我将提交提交.
It creates a merge commit and I submit my commit over it.
现在,当我尝试推送到源时,它表明它将推送我的提交以及合并提交. 但理想情况下,合并提交不应成为远程存储库的一部分.
Now when I am trying to push to origin, it is showing that it will push my commit as well as merge commit. But ideally, merge commit should not be a part of remote repository.
如何避免这种情况?
推荐答案
每当从远程存储库中提取资源时,请使用rebase选项.请按照以下步骤操作,
Use rebase option whenever you pull from remote repository. Please follow the below steps,
- 提交更改-它将在您的本地创建一个新的提交.
- 现在执行
git pull --rebase <remote-name> <branch-name>
. - 基本上,rebase会将您在当前分支HEAD上提交的提交作为补丁删除.然后它将所有远程提交应用在HEAD之上,然后将您的提交应用在它之上.
- 因此,最佳实践是提交更改,然后使用rebase选项提取远程提交.
- Commit your changes - It will create a new commit in your local.
- Now do
git pull --rebase <remote-name> <branch-name>
. - Basically the rebase take out your commits that you committed on the current branch HEAD as a patch. Then it will apply all the remote commits on top of HEAD and then applies your commits on top of it.
- So best practice is to commit changes then pull remote commits by using rebase option.
这篇关于推送到远程时如何避免来自Git pull的合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文