Git 篇

 

 

1、git是什么

git是一款免费的、开源的分布式版本控制系统,可以被用来快速、高效的处理从小到大各种体量的项目。

“Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.. Git is easy to learn and has a tiny footprint with lightning fast performance.It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.”

 

2、资源

菜鸟教程上有Git教程,可供工作上的即时查阅用法、命令等。

 

3、GitHub 原理及上传

git是版本控制系统,当本地有新建或者更新的项目上时,可以上传到github上指定用户的指定项目中。

当需要使用Git时,在相应操作系统里安装git,在linux中,在终端terminal里输入git回车,可以得到一系列的操作提示和说明。

 

% git
start a working area (see also: git help tutorial)

   clone      Clone a repository into a new directory

   init       Create an empty Git repository or reinitialize an existing one

 

work on the current change (see also: git help everyday)

   add        Add file contents to the index

   mv         Move or rename a file, a directory, or a symlink

   reset      Reset current HEAD to the specified state

   rm         Remove files from the working tree and from the index

注释:

a) 此处的index指的是该分支上已经commit内容的快照,git add命令将需要添加的内容添加到快照作为一个临时状态,准备更新、记录到git tree上。

git作为项目管理工具,可以不断地更新、不断提交代码,但是整个项目却没有如本地那样迅速增大硬盘占用量。每次准备更新代码时,在已有状态的快照的基础上继续修改(git add),快照是对当前的文件系统的一个记录,像照相的照片一样。保存各个物体的相对位置。却又是可以细化到其内容细节的,因为有git diff命令可以查看不同提交之间的区别。因为每次的commit提交操作指向git tree上,当前提交的父节点上,操作多了,形成一个链表似的结构,所以可以只保存指针的相对位置(快照),又可以在不同的分支上比较代码差异(git diff)。【关于快照的理解,参考https://www.zhihu.com/question/20828794,他的解释我觉得比较合理,但是我还找不到更原始的官方说明来论证,知道的可以留言交流下】

b) head是一个指针,指向当前操作所在的分支,可以执行回退操作。

 

examine the history and state (see also: git help revisions)

   bisect     Use binary search to find the commit that introduced a bug

   grep       Print lines matching a pattern

   log        Show commit logs

   show       Show various types of objects

   status     Show the working tree status

 

grow, mark and tweak your common history

   branch     List, create, or delete branches

   checkout   Switch branches or restore working tree files

   commit     Record changes to the repository

   diff       Show changes between commits, commit and working tree, etc

   merge      Join two or more development histories together

   rebase     Reapply commits on top of another base tip

   tag        Create, list, delete or verify a tag object signed with GPG

 

collaborate (see also: git help workflows)

   fetch      Download objects and refs from another repository

   pull       Fetch from and integrate with another repository or a local branch

   push       Update remote refs along with associated objects

想看较详细的参数说明,需要到git官方网站的Documentation模块去查找相关命令。

 

4、第一次使用和重复使用git

第一次:

创建工作空间:git init (之后执行 git remote add git@xxx,git将本地库与远程库进行关联)或者 git clone *.git

将本地代码更新添加到快照/索引,使用 git add *,

更新并记录到git库, git commit -m “**”-m表示message,注释说明更改的内容

将本地git库的更新到remote,可以让大家看到或者只是保存作用,git push origin masterorigin 指的是远程的git库,master指的是本地的master分支。如果不想推到master分支,本地使用git checkout -b dev origin/dev在本地建立并切换到与远程分支同样的分支,使用git push (或 git push <远程主机名> <本地分支名>:<远程分支名>)更新

 

重复在一个项目下进行修改:

将远程的代码最新版更新到本地, git pull

修改代码

之后同上

 

 

 

原文地址:https://www.cnblogs.com/xiaoheizi-12345/p/14083502.html