Git常用手冊(cè)

Git 是每個(gè)開(kāi)發(fā)童鞋必須掌握的工具,本文記錄博主日常開(kāi)發(fā)使用 git時(shí),遇到的問(wèn)題和常用的解決方法:

  • No submodule mapping found in .gitmodules for path '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

    1. 當(dāng)我們需要從別的分支上面拉取代碼,并且希望被拉取的commit能夠很好地rebase到當(dāng)前分支,我們就需要用到pull rebase
    2. 示例:從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 clean

      • git 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:

    1. 只需要保留master和develop分支。
    2. 日常開(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"

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 多種多樣的工作流使得在項(xiàng)目中實(shí)施Git時(shí)變得難以選擇。這份教程提供了一個(gè)出發(fā)點(diǎn),調(diào)查企業(yè)團(tuán)隊(duì)最常見(jiàn)的Git工作流。...
    JSErik閱讀 4,609評(píng)論 2 8
  • git常用命令 GIT常用命令備忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章閱讀 8,870評(píng)論 1 26
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆閱讀 572評(píng)論 0 0
  • 前言 今天和產(chǎn)品溝通,要仿照一個(gè)APP,發(fā)現(xiàn)這個(gè)APP上滑時(shí)隱藏navigationBar,雖然也是隱藏但是效果和...
    LeeIn閱讀 1,030評(píng)論 6 21
  • 應(yīng)新聞攝影老師的要求,每周都要交攝影作品,沒(méi)有單反的窮娃子也只能將就用手機(jī)拍,沒(méi)想到,排出來(lái)的照片比我本人好看多了...
    動(dòng)動(dòng)小肥肥閱讀 356評(píng)論 3 1

友情鏈接更多精彩內(nèi)容