GIT常用客户端命令整理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wzl19870309/article/details/86704128

本地仓库管理

  • git clone <remote url>  克隆远程仓库
  • git init <dir>  初始化本地仓库
  • git status  查看仓库状态

本地文件管理

  • git add <filename>  将指定文件加入到缓存区
  • git add <dir>  将指定目录加入到缓存区
  • git add -A       将所有目录及文件加到缓存区
  • git rm --cached <filename>  将指定文件从缓存区移除,不再做版本控制
  • git rm --cached <dir>  -r  将指定目录从缓存区移除
  • git commit file -m '备注'  提交文件到本地仓库
  • git commit file -am '备注'  快速添加并提交文件到本地仓库,等于git add 和git commit file -m '备注' 的集合。注:如果有新文件时,必须先执行git add

分支管理

  • git branch  查看所有分支列表

  • git branch  -avv 查看所有分支列表及状态

  • git branch <branch name>   基于当前分支新建分支,<branch name>为新分支名称

  • git branch <branch name>  <commit id>  基于提交ID创建新分支,<branch name>为新分支的名称

  • git branch -d <branch name> 删除分支

  • git checkout <branch name>  切换分支

  • git merge --no-ff  <branch name> 合并分支

远程仓库管理

  • git remote  查看远程仓库列表
  • git remote  -v  查看远程仓库列表及配置
  • git remote add origin <url>  添加远程仓库关联
  • git remote remove origin  删除远程仓库关联
  • git push --set-upstream origin master  上传新分支到远程仓库
  • git branch --track --set-upstream-to=origin/test test  将本地分支与远程建立关联

常用命令组合:

提交更新

git add -A;
git commit -m '备注';
git push;

删除缓存区文件,这些文件不再需要做版本控制

git rm --cached file_path -r;
git commit -m '备注';
git push;

删除文件

扫描二维码关注公众号,回复: 6135288 查看本文章
git rm file;
git commit -m '备注';
git push;

附(将客户端生成的RSA公钥上传到服务器)

ssh git@git服务器IP 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

猜你喜欢

转载自blog.csdn.net/wzl19870309/article/details/86704128