1. 程式人生 > >git版本控制:如何處理當前分支為*(no branch)的情況

git版本控制:如何處理當前分支為*(no branch)的情況

在使用git branch命令檢視當前環境所在的開發分支時,如果出現*(no branch),則表示當前不處於任何分支,這時可以通過如下幾種方法處理,以便於後續專案版本的管理:

1:git checkout -b 分支名;此時新建立的分支與*(no branch)軟體一樣

2:如果想將*(no branch)合併到主分支master,則首先執行git log命令,記住第一行的id號,然後執行git checkout master命令,此時出現的第一行資訊中也會出現一個id號,與之前執行git log中第一行出現的id號是一致的,此時就已經切換到了主分支上來了,然後執行git merge id將*(no branch)軟體合併到主分支;

如果主分支與*(no branch)軟體內容有差異的檔案比較多,則建議使用第一種方法,如果有差異的軟體不多,則可以使用第二種方法。

# if you have already checked out to master,

# you won't know the commit-ish of your "no branch":

git fsck --lost-found # (to find your <commit-ish>)

git merge <commit-ish>

# if you are still on your "no branch" commit:

git log # (the commit-ish will be on the first line)

git checkout master

git merge <commit-ish

># or

git log | head -n 1 | cut -d ' ' -f 2 | pbcopy

git checkout master

git merge <commit-ish>