git rebase的正确方法 [英] the correct way of git rebase
问题描述
$ git checkout branchA
$ git rebase master
$ git checkout master
$ git merge branchA
ok。
我的问题是我的fork来自其他repo,我添加了三个提交,并且在创建时
git pull --rebase otherRepo master
获取otherRepo提交和我的提交到HEAD的日志,但是当我尝试按
! [被拒绝] HEAD - > master(非快速转发)
错误:未能将某些文件推送到'git@github.com:juanpabloaj / homebrew.git'
为了防止您丢失历史记录,非快进更新被拒绝
在再次按下之前合并远程更改(例如'git pull')。有关详细信息,请参阅git push --help的快速转发部分的
'注意事项。
with
$ git push --force
我可以将我的提交推送到远程回购站,但每次拉是同样的事情,
这是正确的方法吗?
问题在这里:
git pull --rebase otherRepo master
使用 git pull --rebase
时,您在主服务器上的本地提交被重播 在另一个Repo的主人的新提交之上。因此,当你推到你的原点时,这将变成一个非快进推送(参见这里来解释快进合并)。所以git在默认情况下是不允许的。
解决方法很简单,不要使用 - rebase
code> git pull 当从otherRepo拉时:
git pull otherRepo master
for make a rebase normaly I make
$ git checkout branchA
$ git rebase master
$ git checkout master
$ git merge branchA
ok.
my problem is with my fork from other repo, I add three commits and when I make
git pull --rebase otherRepo master
get otherRepo commits and my commits go to HEAD of log, but when I try push
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:juanpabloaj/homebrew.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
with
$ git push --force
I can push my commits to my remote repo, but every time of pull is same thing,
which is the correct way to do it?
Your problem is here:
git pull --rebase otherRepo master
When you use git pull --rebase
, your local commits on master are replayed on top of the new commits in the otherRepo's master. As a consequence of this, when you push to your origin, this becomes a non-fast-forward push (see here for an explaination of fast-forward merges). And so git disallows this by default.
The solution is simple, don't use --rebase
with git pull
when pulling from otherRepo:
git pull otherRepo master
这篇关于git rebase的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!