创建仓库
git init
在当前目录执行,会生成 .git
目录文件,这个和SVN一致。
git commit -m "first commit"
-m
:表示提交描述,必须要填。
git remote add origin git@github.com:test/test.git
git push -u origin master
直接从远端把代码克隆下来。
git clone git@github.com:test/test.git
git status
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
git pull
就等同下面。
git fetch
git merge
git add
添加指定文件:
git add test.txt Test.java
添加所有文件:
git add .
git reset HEAD -- filename
git reset HEAD -- Test.java
这样Test.java将不会被提交到仓库中。
git rm [--cached] fileName
默认会取消并删除文件, --cached
表示不删除文件。
git mv filename1 filename2
该文件必须被add到仓库中才能操作。
git log
$ git log
commit a3eb048ca74c3881f70264de90671d95474f241e (HEAD -> master, origin/master, origin/HEAD, javastack)
Author: javastack <javastack@qq.com>
Date: Fri Sep 22 10:38:37 2017 +0800
commit
commit 75336d6769e79581af8aefe2a15c9b2f305064c5
Author: javastack <javastack@qq.com>
Date: Wed Sep 20 11:19:29 2017 +0800
git branch
git branch test1.0
git checkout
git checkout test1.0
git checkout -b
git checkout -b test1.0
git branch
$ git branch
* master
test1.0
git branch -d
git branch -d test1.0
合并到主干。
git merge
git merge test1.0
git push origin
git push origin test1.0
git diff
git diff master test1.0