关于git的基础使用

git 的基础使用


git 有别于传统的版本管理工具(cvs、svn、tfs)的最大一个特点是分布式,同时弱化权限控制。


有几个概念:

work directory :正在编辑的代码所在目录

unstage:待提交的文件

code repository :代码仓库


git将文件的新增、删除、内容修改等所有相关的操作都定义为"modified"。

提交过程: work directory -> unstage -> code repository


每一次”modified"后,均需要重复上次提交过程,主要命令如下:

work directory -> unstage :git add example.c

unstage -> work directory :  git reset HEAD example.c

unstage -> code repository : git commit -m 'some commit txt'


其它常用操作

  • 撤消修改:

        git checkout -- example.c


  • 查看日志

   git log


  • 回到某个版本

   git reset --hard commit_id



分支相关的操作:

  • 创建与切换:

    git checkout -b  new_branch


  • 显示(含当前工作分支):

    git branch


  • 创建

    git branch new_branch


  • 切换

    git checkout new_branch


  • 删除

    git branch -d new_branch


  • 合并 (在“合并入”的分支中操作,一般是master)

    git merge new_branch


与远程其它code repo的相关操作

  • 克隆

    git clone [email protected]:/example/project.git


  • 推送代码至远程code repo

    git push origin <branch>


  • 从远程code repo获取代码(抓取分支)

    git pull


  • 创建与远程code repo的链接

    git branch --set-upstream dev origin/<branch>




参见: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000


猜你喜欢

转载自blog.csdn.net/zhaozhencn/article/details/41246399