[英]How to push to remote after a git rebase?
您好我成功切除一個vile
承諾使用: git rebase -p 0df8fg5^ 0df8fg5
我正在master
分公司工作。 但是現在當我:
git push
它給:
To git@github.com:my_user/my_repo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:my_user/my_repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git status
給出:
$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 3 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
nothing to commit, working directory clean
它說你已經脫離了master,因為它似乎是git,好像有一個點你有源origin/master
沒有的提交而origin/master
有你沒有的提交。 這一點是您從本地master
副本中刪除提交的點(rebase更改了以下提交的sha)。
要解決這個問題,你必須強制推動 。 但是 ,默認情況下,推送將所有本地分支推送到遠程中具有相同名稱的分支,這意味着強制推送可能會覆蓋其他人的更改。
您可以使用配置設置更改git的默認行為:
git config --global push.default <setting>
其中<setting>
可以是upstream
, current
或simple
以防止推送到您擁有本地版本的所有分支。 Git 2之前的默認matching
具有我正在談論的覆蓋行為,而Git 2以后的默認行為很simple
。 這是git man-page的一段摘錄,描述了每個設置實際上做了什么:
current
- 推送當前分支以更新接收端具有相同名稱的分支。 適用於中央和非中央工作流程。
upstream
- 將當前分支推回到分支,該分支的更改通常集成到當前分支(稱為@ {upstream})。 如果您要推送到通常從中拉出的相同存儲庫(即中央工作流),則此模式才有意義。
simple
- 在集中式工作流程中,像上游一樣工作,如果上游分支的名稱與本地分支不同,則可以更加安全地拒絕推送。當推送到與您通常拉出的遙控器不同的遙控器時,請作為當前工作。 這是最安全的選擇,適合初學者。
此模式將成為Git 2.0中的默認模式。
強制推動的命令是:
git push -f
你必須強迫推動
git push -f
如果其他人也使用遙控器的主分支,這將給他們帶來很多驚喜。 不一定是積極的方式。
在一次改變之后,你需要一般強行推動遠程。
$ git push -f origin master:master
這樣做會強制更新master而不關心快進
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.