I have a repository and some local changes to commit. Before committing, I pulled the changes onto my local using Egit in Eclipse.
我有一个存储库和一些本地更改提交。在提交之前,我使用Eclipse中的Egit将更改提取到我的本地。
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.
现在,当我试图推送到原点时,它表明它将推送我的提交以及合并提交。但理想情况下,合并提交不应该是远程存储库的一部分。
How to avoid this?
怎么避免这个?
4 个解决方案
#1
Use rebase option whenever you pull from remote repository. Please follow the below steps,
从远程存储库中提取时,请使用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 --rebase
基本上,rebase会将您在当前分支HEAD上提交的提交作为补丁。然后它将在HEAD顶部应用所有远程提交,然后在其上应用您的提交。
因此,最佳做法是提交更改,然后使用rebase选项提取远程提交。
#2
When you have uncommitted changes, you can do,
如果您有未提交的更改,则可以执行此操作,
git stash
git pull --rebase <remote> <branch>
git stash pop
#3
You can run
你可以跑
git config --global branch.autosetuprebase always
to make git pull --rebase
the default behaviour for git pull.
使git pull --rebase是git pull的默认行为。
#4
The usual strategy is to work on a branch. When the remote master changes, pull the changes to master and instead of merging, rebase the branch.
通常的策略是在分支机构工作。当远程主服务器更改时,将更改拉到主服务器而不是合并,重新绑定分支。
See Git Rebase at Atlassian.
请参阅Atlassian的Git Rebase。
#1
Use rebase option whenever you pull from remote repository. Please follow the below steps,
从远程存储库中提取时,请使用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 --rebase
基本上,rebase会将您在当前分支HEAD上提交的提交作为补丁。然后它将在HEAD顶部应用所有远程提交,然后在其上应用您的提交。
因此,最佳做法是提交更改,然后使用rebase选项提取远程提交。
#2
When you have uncommitted changes, you can do,
如果您有未提交的更改,则可以执行此操作,
git stash
git pull --rebase <remote> <branch>
git stash pop
#3
You can run
你可以跑
git config --global branch.autosetuprebase always
to make git pull --rebase
the default behaviour for git pull.
使git pull --rebase是git pull的默认行为。
#4
The usual strategy is to work on a branch. When the remote master changes, pull the changes to master and instead of merging, rebase the branch.
通常的策略是在分支机构工作。当远程主服务器更改时,将更改拉到主服务器而不是合并,重新绑定分支。
See Git Rebase at Atlassian.
请参阅Atlassian的Git Rebase。