2012-09-02 42 views
20

如何解決此問題?我正在嘗試提交,但是我得到了下面的錯誤。Git非快進更新被拒絕合併遠程更改

混帳推起源monty_svm_dev

To [email protected]: ! [rejected]  monty_svm_dev -> monty_svm_dev 
(non-fast-forward) error: failed to push some refs to 
'[email protected]:/mygit.git' To prevent you from losing history, 
non-fast-forward updates were rejected Merge the remote changes before 
pushing again. See the 'Note about fast-forwards' section of 'git 
push --help' for details. [email protected]:~/mypath# 

回答

25

git pull origin monty_svm_dev第一

現在的情況是,該遙控器具有更近的比你的分支修改。

因此,在您可以push您的更改之前,您需要首先獲取併合並遠程更改。

你可以做一個git checkout your_branch做這一點,則:

git fetch origin your_branch然後
git merge your_branch

git pull origin your_branch # fetch and merge in one operation 

如果你的分支是高手,還是你的支行名稱(似乎是你的情況我認爲是monty_svm_dev

一旦做到這一點(和任何衝突解決),你可以做一個git push origin monty_svm_dev

+0

或者OP可能已經重新啓動了它們的分支。 – knittl

+0

我聽說拉不好,因爲它會以你通常不想要的方式合併。 Peronally,我喜歡保持我的歷史線性。當我遇到與提問者相同的錯誤時,我該如何實現? –

+0

我試過#git pull origin devops_branch_22112016出現錯誤:對以下文件的本地更改將被合併覆蓋: www/index.html 請在提交更改或隱藏它們後再進行合併。 正在中止 –

2

它基本上是因爲當你

git pull

從一個分支,兩個操作發生提取和合並。現在,如果您的本地有一些變化,那麼在您提交更改之前,git將不允許您推送它。

此外,如果遠程的變化仍然沒有被拉到本地並且合併,那麼就會出現這個問題,所以您需要再次拉動然後按下它。如果它不能解決問題,請回復

0

做一個Git拉。然後它會將遠程分支中最近的代碼更改帶入本地。那麼你可以推動你的改變。

+1

已經給出了這個答案,更詳細的說明(https://stackoverflow.com/a/12236918/1590950)。如果你想擴大並且讓你的答案提供一些其他的不會繼續。 – indivisible

0

當用戶忘記在命令git commit後忘記發出git push命令時,會出現此問題。使用git時,請務必確保基本步驟。

In an ideal cycle while working with git, always check the following git commands were used sequentially in the following order:

git pull 
git add 
git commit 
git push 

我個人避免廣大發布有關堆棧git的問題,因爲我總是吻合我的git命令的活動還與上面的序列。

我創建的首字母縮寫,以確保我不會忘記,我hopoing同樣可以是這是很有用:

pacp (read it as: pack push where (p=git push, a=git add, ck=git commit, push=git push).

我的方式來記住混帳推,添加,提交,拉是:

get pack push (meaning: git the pack and then push).

總之記住要「包」,然後「推」。

解決的問題: 我想補充一點,是我最常用的恢復Git命令:

git checkout -- path/to/file/fileName.something #undo changes in file 

The above undoes the changes in a file...similar can be applied for multiple files using * for file name, similarly can be applied to multiple directories separated by space.

git reset filename.txt 

The above removes the file from stage...after this command we can safely do git commit and git will only commit those files we are in stage which means the file "filname.txt" won't get committed)

git pull origin your_intended_branch 

變化與從your_intended_branch最新合併這基本上合併了你承諾但沒有推動的變化。一旦一切順利,只需按下:

git push