git常用操作

一、新建分支及查看

git branch <local_branch>
git checkout -b <local_branch>
git branch
git branch -a

二、删除分支

git branch -d <local_branch>
git branch -r -d origin/<remote_branch>

三、追踪远程分支

git clone <git_url>
git checkout --track origin/<remote_branch>(适用于本地无分支)
git push --set-upstream origin <remote_branch>(适用于远程无分支)
git checkout -b <local_branch> origin/<remote_branch>(适用于本地无分支)
git branch --set-upstream <local_branch> origin/<remote_branch>(适用于本地及远程均有分支)
git branch -u origin/<remote_branch>(适用于本地和远程均有分支, 设置当前分支)
git branch --set-upstream-to=origin/<remote_branch>(适用于本地远程均有,设置当前分支)
git branch --unset-upstream master(取消之前的追踪)

git branch -vv

四、远程分支合并

git checkout <local_branch>
git pull origin <remote_branch>
git checkout master
git merge <local_branch>


五、本地有改动pull

git stash
git stash save <msg>
git pull
git stash show
git stash list
git stash pop
git stash apply stash@{num}
git stash drop stash@{num}
(备份本地修改文件, 删除修改部分, pull, 增加修改部分)
(.git/refs/stash最后一个stash节点对应的指针, .git/log/refs/stash全部节点对应指针)
(WIP: work in progress)

六、git 回退
git log
git reset --hard <commit_id>

七、git配置信息
git config --list(-l)
git config user.name
git config user.email

git config --global user.name <your_name>
git config --global user.email <your_email>

git config --global --replace-all user.name <your_name>
git config --global --replace-all user.email <your_email>

git config --global --unset <field_name>

八、本分支删除另一分支在本分支的文件
git rm --cached <file-name> <dir-name> -rf
rm <file-name> <dir-name> -rf



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值