Git使用简介
Git是分布式版本管理工具,版本管理工具常见的还有hg/svn,但是Git功能最强大,普及程度最广。这里记录一下常见的命令
1,基本概念
clone
git clone <code_repository_url> <set_folder_name>
从代码仓复制代码到本地。第一个参数是git的url,支持https/ssh,第二个是本地项目文件夹名。
用https的url可以保存账户密码,用ssh的url可以直接保存一对密钥。
fetch
抓取远端仓库的所有分支
git fetch
branch
git branch
查看当前工作路径的所有分支
git branch <branch_name>
创建目标分支
checkout
git checkout <branch_name>
切换到对应工作分支。代码改动量
diff
git diff
查看当前改动
add
将当前改动记录到暂存区。
git add .
commit
提交暂存区的代码改动
git commit -m “<commit_messges>”
push
推送代码
git push origin/<branch_name> <branch_name>
pull
拉最新的代码到本地
git pull <branch_name> <origin_branch_name>
clean
将未提交的所有改动全部清除,回退到最后一次提交的节点
git clean -dxf
2,使用案例:创建新分支并合入修改的代码
git clone xxx.git git_repo_clone
下载代码
git branch Feature/personal_add_function1
创建分支
git checkout Feature/personal_add_function1
切换分支
git push origin Featrue/personal_add_function1
推送分支到远端
<coding… … >
git diff
查看代码变化
git add .
将代码改动记录入暂存区。
git commit -m “modify 1st: add some functions.”
提交代码。
git push origin Feature/personal_add_function1
推送代码到远端