git 常用命令集合

检出远端仓库
git clone username@host:/path/to/repository


添加本地修改
git add <filename>
git add .

提交修改到本地
git commit -m "代码提交信息"


推送修改到服务器
git push origin master


列出所有分支
git branch --all


新建分支
git checkout -b local_branch

新建远程分支(在建立本地分支后)

git push origin local_branch


获取远程分支(两种方式)
git checkout -b local_branch remote_branch
或者
git checkout --track remote_branch


切换分支
git checkout master


删除分支
git branch -d test_branch


合并分支
git merge <branch>


从服务器更新本地仓库
git pull


取消本地改动
git checkout -- <filename>


丢弃本地所有改动
git fetch origin
git reset --hard origin/master


更换远端仓库地址
git remote set-url origin <repository>


Merge时常用的命令
1.GUI tool:
git mergetool 

2.command line:
接受服务器的修改:
git checkout --theirs <filename>

保留自己的修改:
git checkout --ours <filename>


回退单个文件到指定版本
git checkout <commit_number> <filename>


origin是远程仓库的一个别名
使用命令
git remote -v

可以查看origin指向的远程仓库
origin  ssh://lawrence.li@xxx.com/gitroot/icm_hcdh (fetch)
origin ssh://lawrence.li@xxx.com/gitroot/icm_hcdh (push)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值