git常用操作

设置

快捷命令设置

git config --global alias.st status
git config --global alias.ci "commit -a" 
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.dc dcommit
git config --global alias.rb rebase

彩色交互界面

git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto
git config --global core.autocrlf input

 

设置用户个人信息

请修改成你自己的,不要照抄

git config --global user.name "da.peng666" 
git config --global user.email "da.peng666@foxmail.com" 

开发常用操作

克隆一个项目到本地

git clone git://your-git-server/your-project.git your-project

设置远程仓库

# 添加(origin 为一个标示,可以随意更换)
git remote add origin  git://your-git-server/your-project.git
# 删除
git remote remove origin

操作远程仓库

# 提交本地修改(将本地修改提交到远程的master分支)
git push -u origin master
# 合并远程修改(将远程的master分支合并进来)
git pull origin master
# 删除远程仓库里的分枝
git push :branch

基本操作

# 提交修改
git add /path/to/file
git commit -m reason
# 提交全部修改
git commit -a -m reason
# 创建本地分枝
git co -b branch_name
# 查看分枝
git branch
# 删除分枝
git branch -D branch_name
# 查看分支之间的差异
git diff master branch
# 查看最新版本和上一个版本的差异(一个^表示向前推进一个版本)
git diff HEAD HEAD^
# 查看状态
git status
# 合并分支
git pull . branch
# 销毁自己的修改
git reset --hard

还可以和svn交互

# 从subversion仓库中克隆
git svn clone https://googlecode.com/svn
# 将本地修改提交到subversion仓库
git svn dcommit
# 导入新的subversion更新
git svn rebase

协同工作流程

1. 在本地修改确认后,需要提交到主库,使用
git push 
如果远程提交失败,失败信息如:
To git@www.yongche-inc.com:che.git
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@www.yongche-inc.com:che.git'
这时提示你主库下可能有文件冲突,

2. 这时需要执行
git pull
把主库最新版本同步到本地,如果提示如:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From git@www.yongche-inc.com:che
   0c94dbe..52a81fe  master     -> origin/master
Auto-merged readme
CONFLICT (content): Merge conflict in readme
Automatic merge failed; fix conflicts and then commit the result.
这是提示你有文件readme和主库有冲突,以后就需要手动处理冲突。

3. 文件中冲突,git以如下方式提示给你
<<<<<<< HEAD:readme
test by wangbai and yancan and someone haha
=======
test by wangbai and yancan and somthing
>>>>>>> 52a81fe3acf426bbae164a00ba3413550e056672:readme
4. 手动解决冲突后,需要重新commit,然后push
git commit
git push
如显示:
Counting objects: 10, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 639 bytes, done.
Total 6 (delta 0), reused 2 (delta 0)
To git@www.yongche-inc.com:che.git
   52a81fe..bb31966  master -> master
提交成功
posted @ 2016-09-14 10:13  大鹏666  阅读(608)  评论(0编辑  收藏  举报