您的位置:首页 > 其它

git 常用命令集合

2015-06-15 11:37 309 查看
检出远端仓库
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: