2017-09-21 72 views
0

我們剛剛開始使用git前幾天,我們決定我們所有的團隊將直接從本地推到master分支。 因此,我們每個人都將負責我們的提交可以運行。Git合併遠程追蹤分支問題

到目前爲止,我們遇到了一個問題,那就是有大量的提交信息"Merge remote-tracking branch 'refs/remotes/origin/master'" in history。這發生在我們將git fetch和git合併到最新版本時,並將提交推送給master。

這對我們來說似乎不是件好事。有什麼方法可以克服它嗎? 我們有研究,並認爲它可以通過使用rebase(有些人說如果不瞭解git的話就不應該使用)。但不知道如何完全做到這一點。

希望有人在stackoverflow可以幫助我們。特別是:
1)在推送之前從服務器獲取和合並最新更新時要完成的實際步驟是什麼。
2)我們是否應該繼續提交消息"Merge remote-tracking branch 'refs/remotes/origin/master'" in history進行子序列推送,或者找到一種方法讓它在提交歷史記錄中未來推送?

回答

0

您的團隊應該從主人分支出來,並將他們的分支合併到--ff-only旗幟上。他們將使用rebase來確保他們始終使用最新版本的主人。 例如

git checkout master 
git pull # now master is up to date 

git checkout -b my-feature 
# work work work 
git add . 
git commit -m "I did some work" 

# other people were making changes at the same time, 
# and some new features got added to master. 

git checkout master 
git pull # now master is up to date again 
git checkout my-feature 
git rebase master 
# ^^^^^^^^^^^^^^^ this makes it seem like "I did some work" 
# happened on the most recent version of master 

# ready to merge my work onto master 
git checkout master 
git merge my-feature --ff-only # ff-only prevents the merge commit that you're trying to avoid 

git push 
# now everyone on the team can see my changes 
相關問題