Git常用手册

Git 是每个开发童鞋必须掌握的工具,本文记录博主日常开发使用 git时,遇到的问题和常用的解决方法:

  • 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

  • 拉取其他分支代码到当前分支:Git pull rebase

    1. 当我们需要从别的分支上面拉取代码,并且希望被拉取的commit能够很好地rebase到当前分支,我们就需要用到pull rebase
    2. 示例:从develop拉取代码到当前分支:
      • 确保本地分支代码和develop都已经push到origin

      • git pull --rebase origin develop
        把develop分支代码拉取到当前分支,此时会发现当前分支和develop分支代码并没有rebase,还是在两条不同的线上,拉取完成后会发现如下的一些提示:
        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分支强行push到origin
        git push 会导致错误,因为使用pull rebase操作会生成两个不同的分支(Your branch and 'origin/feature/music' have diverged)

  • Git分支管理策略
    1.推荐阅读 《Git分支管理策略 - 阮一峰的网络日志
    2.Git workflow:

    1. 只需要保留master和develop分支。
    2. 日常开发时,从develop上面开一个feature分支,完成开发后,按需merge到develop分支中,merge成功后,可以删除feature分支。 3. 发布前,使用release分支 4. 产品上线后,使用从master分支fork出hotfix分支,完成bug修复后,merge到master和develop分支。
  • Github pull request
    1.《Mort | Pull Request的正确打开方式(如何在GitHub上贡献开源项目)》 -- 原文404,可以参考转载

  • 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

  • 多个github账号的管理:
    https://gist.github.com/jexchan/2351996
    本人常年使用公司和个人的Github帐号,在正确配置github帐号后,可以用命令行进行帐号切换。

  • 清除git缓存:
    有的时候会出现.gitignore文件不起作用的情况,需要清理git缓存:
    $ git rm --cached -r FOLDER_NAME
    $ git add .
    $ git commit -m “COMMIT_MSG"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容