git 备忘

1. 初始化仓库

  1. 创远程仓库

  2. 在项目中git init

  3. 关联远程仓库 git remote add origin 地址

  4. git add .

  5. git commit -m “内容”

  6. 更新项目,避免与远程仓库冲突

    1
    git pull --rebase origin master
  7. git push origin master
    
    1
    2
    3
    4
    5
    6



    ### 2. 反斜杠错误'\\'

    git 2.24版本存在这样的问题,更新git项目中的子模块会报错,导致不成功,错误如下
    error: filename in tree entry contains backslash: '\'
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    ![](https://qiniu.lgx123.cn/20200210214233-1.png)

    **解决办法:**

    - 升级git版本到2.25或者降到2.23都可解决此问题
    - 禁用[core.protectNTFS](https://translate.googleusercontent.com/translate_c?depth=1&hl=zh-CN&prev=search&rurl=translate.google.com&sl=en&sp=nmt4&u=https://git-scm.com/docs/git-config&xid=17259,15700022,15700186,15700190,15700259,15700271,15700302&usg=ALkJrhgI-ExxieOLS4BgBJejN9E-jIKJ3w#Documentation/git-config.txt-coreprotectNTFS) : `git config --global core.protectNTFS false`



    ### 3. 设置提交模板
    git config commit.template [模板文件名]
    1
    2
    3
    4
    5
    6



    ### 4. 删除分支

    先切到master
    git checkout master
    1
    2

    查看本地已有的和远端的所有分支
    git branch -a
    1
    2

    #### 4.1 删除远程分支
    git push origin --delete 分支名
    1
    2

    #### 4.2 删除本地分支
    git branch -d 分支名 //有可能会提示使用-D的命令 git branch -D 分支名
    1
    2
    3
    4
    5
    6
    7
    8



    ### 5. 远端分支已经删除,本地依旧能看到

    1.使用git branch -a查看本地和远程分支,会发现有些已经在远程仓库删除的分支,本地依旧能看到

    2.查看本地分支与远程分支的关系
    git remote show origin
    1
    2

    3.删除远程仓库已经不存在的分支
    git remote prune origin
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16



    ### 6. TortoiseGit设置ssh方式

    1.进入tortoise的设置界面-->点击 `Re-run First Start Wizard`

    ![](https://qiniu.lgx123.cn/20200217000941-1.png)

    一直next(下一步),直到 Authentication an credential store界面,设置ssh为OpenSSH方式,完成

    ![](https://qiniu.lgx123.cn/20200217001227-1.png)

    ### 7. 已提交的项目添加.gitignore文件

    1.清除本地项目缓存
    git rm -r --cached .
    1
    2

    2.新建.gitignore文件
    touch .gitignore
    1
    2

    3.再次提交所有文件
    git add . git commit -m "add ignore"
    1
    2

    4.提交到远端
    git push
    1
    2
    3
    4
    5
    6



    ### 8. 修改本地以及远程分支名称

    1. 重命名本地分支
    git branch -m oldBranch newBranch
    1
    2

    2. 删除远端分支
    git push --delete origin oldBranch
    1
    2

    3. 将本地已重命名的分支推到远端
    git push origin newBranch
    1
    2

    4. 切换到新分支
    git checkout newBranch
    1
    2

    5. 关联本地和远端的分支
    git branch --set-upstrean-to=origin/newBranch
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11



    ### 9. tag操作

    - 列出tag

    ```git
    git tag -l
    git tag -l "v1.1.1*" //筛选出v1.1.1开头的tag
    git ls-remote -t //查看远端tags
  • 创建tag
1
2
3
4
git tag -a [tagName] -m '[注释]'

//给某次提交加tag
git tag -a [tagName] [commitid]
  • 推送tag到远端
1
2
3
4
git push origin [tagName]

//推送所有本地tag到远端
git push origin --tags
  • 删除tag

    • 删除本地tag

      1
      git tag -d [tagName]
    • 删除本地所有tag

      1
      2
      3
      4
      git tag -l|xargs git tag -d

      //拉取远端所有tag
      git fetch origin --prune
    • 删除远端tag

      1
      2
      3
      4
      //方式一
      git push origin :refs/tags/[tagName]
      //方式二
      git push origin --delete [tagName]

10. SSL certificate problem

在clone 仓库的时候报:SSL certificate problem: unable to get local issuer certificate

大概就是 SSL证书过期导致的

解决办法:

直接关闭SSL证书校验

1
git config --global http.sslVerify false