git的一些常用方法


  1. 设置用户信息

    $ git config --global user.name itaken
    
    $ git config --global user.email regelhh@gmail.com
  2. git 别名

    $ git config --global alias.br branch
    
    $ git config --global alias.ci commit
    
    $ git config --global alias.st status
  3. 仓库状态

    $ git st -s
    M  src/views/index.vue
    A  src/views/login.vue
    A  src/views/profile.vue
    A  src/views/sidebar.vue
       ...
  4. 删除(取消)提交内容,并保留本地文件

    $ git rm -rf node_modules --cache

    -r 目录循环 -f 强制删除

  5. .gitignore忽略列表 ^1

    $ cat .gitignore
    node_modules/
  6. 提交的”补丁”

    $ git commit -m "版本内容"
    
    $ git add someting
    $ git commit --amend

    --amend这个会将本次commit的内容补齐到上一次commit中

  7. 修改远程url set-url

    hexo_tech_wiki  ‹master*› $ git remote -v                                                           1 ↵
    origin    http://localhost:3000/itaken/hexo_tech_wiki.git (fetch)
    origin    http://localhost:3000/itaken/hexo_tech_wiki.git (push)
    hexo_tech_wiki  ‹master*› $ git remote set-url origin http://localhost:3001/itaken/hexo_tech_wiki.git
    hexo_tech_wiki  ‹master*› $ git remote -v                                                            
    origin    http://localhost:3001/itaken/hexo_tech_wiki.git (fetch)
    origin    http://localhost:3001/itaken/hexo_tech_wiki.git (push)

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录