Git 常用操作


记录一些git常用操作,会保持更新。如有错误请指出。

分支操作

新建本地和远程分支并上传

  1. 新建本地分支"new_local_branch"
git checkout -b new_local_branch
  1. 更新分支程序,并将更新部分加入缓存区,并写commit
git add 
git commit -m "XXXX"
  1. 新建远程分支“new_remote_branch",并将本地分支提交到远程分支。
git push origin new_local_branch:new_remote_branch

origin是远程主机名,后面先是之前新建的本地分支名,后跟一个:,最后是新的远程分支名。

这一步有简略写法。

git push -u origin new_branch

-u 是–set-upstream的缩写形式,origin是远程主机名, new_branch为新建的远程分支,这里新建的远程分支名需要与本地分支名相同。

下载远程分支到新的本地分支

  1. 下载远程分支remote_branch到新建的本地分支new_local_branch下
git checkout -b new_local_branch origin/remote_branch

重命名本地分支与远程分支

  1. 重命名本地分支
git branch -m new_branch_name
  1. 重命名远程分支。
    先删除用旧名的远程分支old_remote_branch
git push origin -d old_remote_branch

再将新的本地分支提交到新的远程分支

git push origin -u new_branch_name
  1. 查询本地分支指向的远程分支
git branch -vv

删除本地分支和远程分支

  1. 删除本地分支local_branch
git branch -d local_branch
  1. 删除远程分支remote_branch
git push origin -d remote_branch

缓存区操作

清空add的缓存区

  1. 清空所有缓存区内容
git reset --mixed

–mixed 指清空stage/cache/index区域

  1. 删除add进缓存区的文件new_file
git reset new_file
  1. 可以使用git rm 删除文件,但要注意
git rm --cached new_file

可以去除add进缓存区的文件new_file,并且不删除物理文件.

git rm -f new_file

则是既删除缓存区new_file,也会将new_file的物理文件删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值