Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
Torvalds 开始着手开发 Git 是为了作为一种过渡方案来替代 BitKeeper,后者之前一直是 Linux 内核开发人员在全球使用的主要源代码工具。开放源码社区中的有些人觉得BitKeeper 的许可证并不适合开放源码社区的工作,因此 Torvalds 决定着手研究许可证更为灵活的版本控制系统。尽管最初 Git 的开发是为了辅助 Linux 内核开发的过程,但是我们已经发现在很多其他自由软件项目中也使用了 Git。例如 很多 Freedesktop 的项目迁移到了 Git 上。
github
github是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名github。 github于2008年4月10日正式上线,除了git代码仓库托管及基本的 Web管理界面以外,还提供了订阅、讨论组、文本渲染、在线文件编辑器、协作图谱(报表)、代码片段分享(Gist)等功能。目前,其注册用户已经超过350万,托管版本数量也是非常之多,其中不乏知名开源项目 Ruby on Rails、jQuery、python 等。
gitlab
GitLab是一个利用Ruby on Rails开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。 它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。 GitLab要求服务器端采用Gitolite搭建(为了方便安装,现已经用gitlab-shell代替Gitolite)
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # # Initial commit # # Changes to be committed: # new file: test.txt #
这里出来一个vi的界面填写注释,如果直接保存退出会终止提交并提示以下内容。
1 2
➜ mygit git:(master) ✗ git commit Aborting commit due to empty commit message.
现在输入注释后进行提交:
1 2 3 4 5 6 7
➜ mygit git:(master) ✗ git commit [master (root-commit) db19d2d] initial commit 1 file changed, 1 insertion(+) create mode 100644 test.txt ➜ mygit git:(master) git status On branch master nothing to commit, working tree clean
还有一种更加简便的方式:将当前目录下有修改的文件进行add操作并提交: git commit -am 'add another line'
➜ mygit git:(master) vi test.txt ➜ mygit git:(master) ✗ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a") ➜ mygit git:(master) ✗ git checkout -- test.txt ➜ mygit git:(master) git status On branch master nothing to commit, working tree clean
➜ mygit git:(master) git rm test2.txt rm 'test2.txt' ➜ mygit git:(master) ✗ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
➜ mygit git:(master) ✗ git reset HEAD test2.txt Unstaged changes after reset: D test2.txt ➜ mygit git:(master) ✗ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
deleted: test2.txt
no changes added to commit (use "git add" and/or "git commit -a") ➜ mygit git:(master) ✗ ls test.txt ➜ mygit git:(master) ✗ git checkout -- test2.txt ➜ mygit git:(master) git status On branch master nothing to commit, working tree clean ➜ mygit git:(master) ls test.txt test2.txt
上面又测试一系列命令,用reset和checkout命令恢复了删除的文件。
下面进行真正的删除,并提交。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
➜ mygit git:(master) git rm test2.txt rm 'test2.txt' ➜ mygit git:(master) ✗ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
➜ mygit git:(master) echo'hello world' > test2.txt ➜ mygit git:(master) ✗ ls test.txt test2.txt ➜ mygit git:(master) ✗ git add test2.txt ➜ mygit git:(master) ✗ git commit -m 'create a file' [master 1a7fc91] create a file 1 file changed, 1 insertion(+) create mode 100644 test2.txt ➜ mygit git:(master) rm test2.txt ➜ mygit git:(master) ✗ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
deleted: test2.txt
no changes added to commit (use "git add" and/or "git commit -a") ➜ mygit git:(master) ✗ git checkout -- test2.txt ➜ mygit git:(master) git status On branch master nothing to commit, working tree clean ➜ mygit git:(master) ls test.txt test2.txt
➜ mygit git:(master) git mv test.txt test2.txt ➜ mygit git:(master) ✗ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)