Git 是每個(gè)開(kāi)發(fā)童鞋必須掌握的工具,本文記錄博主日常開(kāi)發(fā)使用 git時(shí),遇到的問(wèn)題和常用的解決方法:
-
No submodule mapping found in .gitmodules for path 'Frameworks/XXX'
- 參考:http://stackoverflow.com/questions/1260748/how-do-i-remove-a-git-submodule
- $git submodule
- $git rm 'Frameworks/XXX'
-
檢查非法的branch名字(不允許分支名包含):
Have a path component that begins with "."
Have a double dot ".."
Have an ASCII control character, "~", "^", ":" or SP, anywhere
End with a "/" - End with ".lock"
Contain a "" (backslash -
拉取其他分支代碼到當(dāng)前分支:Git pull rebase
- 當(dāng)我們需要從別的分支上面拉取代碼,并且希望被拉取的commit能夠很好地rebase到當(dāng)前分支,我們就需要用到pull rebase
- 示例:從develop拉取代碼到當(dāng)前分支:
確保本地分支代碼和develop都已經(jīng)push到origin
git pull --rebase origin develop
把develop分支代碼拉取到當(dāng)前分支,此時(shí)會(huì)發(fā)現(xiàn)當(dāng)前分支和develop分支代碼并沒(méi)有rebase,還是在兩條不同的線上,拉取完成后會(huì)發(fā)現(xiàn)如下的一些提示:
On branch feature/music
Your branch and 'origin/feature/xxx' have diverged,
and have 9 and 6 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory cleangit push -f
把本地分支和develop分支強(qiáng)行push到origin
git push 會(huì)導(dǎo)致錯(cuò)誤,因?yàn)槭褂胮ull rebase操作會(huì)生成兩個(gè)不同的分支(Your branch and 'origin/feature/music' have diverged)
-
Git分支管理策略
1.推薦閱讀 《Git分支管理策略 - 阮一峰的網(wǎng)絡(luò)日志》
2.Git workflow:- 只需要保留master和develop分支。
- 日常開(kāi)發(fā)時(shí),從develop上面開(kāi)一個(gè)feature分支,完成開(kāi)發(fā)后,按需merge到develop分支中,merge成功后,可以刪除feature分支。 3. 發(fā)布前,使用release分支 4. 產(chǎn)品上線后,使用從master分支fork出hotfix分支,完成bug修復(fù)后,merge到master和develop分支。
Github pull request
1.《Mort | Pull Request的正確打開(kāi)方式(如何在GitHub上貢獻(xiàn)開(kāi)源項(xiàng)目)》 -- 原文404,可以參考轉(zhuǎn)載-
Github Repo Migration:
- Github fork repo
- Github import repo
-
Git 修改commit message:
- git commit --amend -m "New commit message"
查找commit message:
git log --oneline | grep PATTERN多個(gè)github賬號(hào)的管理:
https://gist.github.com/jexchan/2351996
本人常年使用公司和個(gè)人的Github帳號(hào),在正確配置github帳號(hào)后,可以用命令行進(jìn)行帳號(hào)切換。清除git緩存:
有的時(shí)候會(huì)出現(xiàn).gitignore文件不起作用的情況,需要清理git緩存:
$ git rm --cached -r FOLDER_NAME
$ git add .
$ git commit -m “COMMIT_MSG"