业余时间读Pro Git整理……
1.Installing Git
If you’re on Fedora for example, you can use yum:
$ sudo yum install git-all
If you’re on a Debian-based distribution like Ubuntu, try apt-get:
$ sudo apt-get install git-all
Installing on Windows:
https://git-scm.com/download/win
2.Geting a Git Repository
**2.1 Initializing a Repository in an Existing Directory**
进入项目的目录下,输入命令: $ git init
这仅仅是在你的目录下创建了一个包含必要库文件的.git的子文件夹。如果想跟踪这些 文件你还需要一些 git add 命令,如下:
$ git add *.c
$ git add LICENSE
$ git commit -m 'initial project version'
**2.2 Cloning an Existing Repository**
你可以使用 git clone [url] 来克隆一个仓库,例如,你可以这样做:
$ git clone https://github.com/libgit2/libgit2
如果你想要把仓库克隆到一个你自己命名的文件夹而非“libgit2”,你可以使用如下命令:
$ git clone https://github.com/libgit2/libgit2 mylibgit
3.Recording Changes to the Repository
**3.1 Checking the Status of Your Files**
你可以用git status命令来检查文件处于某种状态,如果你在刚刚克隆之后运行此命令,你应该能够看到如下内容:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
**3.2 Tracking New Files**
你可以使用git add命令开始跟踪一个新的文件,你可以运行下面的命令来开始跟踪README文件:
$ git add README
**3.3 Staging Modified Files(暂存修改后的文件)**
如果你修改了一个叫CONTRIBUTING.md的文件之后运行了 git status 命令,你将会看到如下的内容:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: README
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: CONTRIBUTING.md
此时CONTRIBUTING.md文件处于未暂存的状态,让我们用 git add 命令来缓存它:
$ git add CONTRIBUTING.md