2017-05-04 104 views
0

我在嘗試在GIT上推送項目時遇到以下問題。如何在GIT推送期間忽略遠程更改?

推它,我得到這個錯誤信息:

$ git push origin master 
To https://bitbucket.org/MyAccount/my-project.git 
! [rejected]  master -> master (fetch first) 
error: failed to push some refs to 'https://[email protected]/MyAccount/my-projec.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 integrate the remote changes 
hint: (e.g., 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

如此看來,糾正我,如果我做錯了斷言,這對我的遠程倉庫也有,我還沒有在我的本地庫採取的變化和它建議我執行拉動來獲得這些變化。

這對我來說是一個問題,因爲本地版本是我的應用程序的最後一個明確版本,我不能冒險從遠程存儲庫中覆蓋某些舊的和錯誤的東西(或由someoneelse創建)。

我可以指定推送本地內容而不考慮遠程更改嗎?或者我該如何檢查我最後的本地提交和遠程內容之間的區別?

+0

[Force git push覆蓋遠程文件]可能重複(http://stackoverflow.com/questions/10510462/force-git-push-to-overwrite-remote-files) – 1615903

回答

1

是的,據你所知,這是因爲遠程master分支有新版本(可能由你的同事推送)。除了強制推送外,您不能忽略新版本,否則會導致新版本丟失。

你應該拉新版本從遠程到本地,和重訂的新版本上面的unpushed提交和保留衝突文件作爲本地版本若有混帳拉在衝突期間,該命令可以使用

git pull origin master --rebase -X theirs 

您可以使用跟蹤分支來檢查遠程是否有新版本。 master分行通常會跟蹤到origin/master(您可以通過git branch –vv查詢)。然後你可以使用git status,git會比較本地主和遠程分支。