1.查看操作日记
《git log》用于查看操作日记详情。因为Git是分布式的,采用SHA1这样的版本号可有效的防止版本冲突。
[cpp]
#查看操作日记,底下那串长长的数据就是SHA1 ID,表示当前版本号
$ git log
commit aea0365712908805bc28540b4db9fd2f15360a8b
Author: Jacky <fusijie@vip.qq.com>
Date: Fri Sep 27 15:15:48 2013 +0800
init AddFiles
2.修改项目内容
[cpp]
#修改JackyData01内容
$ echo "HelloGit" > JackyData01
3.查看当前状态
[cpp]
#查看版本库状态,可以看到红色的JackyData01被修改过
$ 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: Jackydata01
#
no changes added to commit (use "git add" and/or "git commit -a")
4.提交修改
这里使用《git commit -a -m “提交信息”》可以省掉先放到暂存区的操作,直接提交。
[cpp]
#直接提交修改
$ git commit -a -m "modify JackyData01"
[master cba8800] modify JackyData01
1 file changed, 1 insertion(+), 2 deletions(-)
5.查看操作日记
还用《git log》,不过这次我们给它添加一个参数,这样浏览起来会方便很多。
[cpp]
#单行显示,只显示版本号和备注
$ git log --pretty=oneline
cba8800f2daaf4075a506b6d763798ea15ba11cc modify JackyData01
aea0365712908805bc28540b4db9fd2f15360a8b init AddFiles
6.查看不同
《git diff》用于比较上一次提交和当前版本的差异。
[cpp]
#修改JackyData02的内容为HelloGit
$ echo "HelloGit" > JackyData02
#使用Git diff查看差异,可以看到HelloJacky被删除了,而HelloGit被添加了
$ git diff
diff --git a/JackyData02 b/JackyData02
index 85d5336..1da19b8 100644
--- a/JackyData02
+++ b/JackyData02
@@ -1 +1 @@
-HellloJacky
+HelloGit
7.提交修改并打开Git GUI界面
《gitk --all》用于打开Git的GUI界面。
[cpp]
#提交修改
$ git add . && git commit -m "modify JackyData02"
[master a5f6601] modify JackyData02
1 file changed, 1 insertion(+), 1 deletion(-)
#打开GUI界面
$ gitk --all
8.修改提交信息
使用《git commit --amend》可以修改上次提交的信息。
[cpp]
#重新修改上次提交信息
$ git commit --amend -m "amend modify JackyData02"
[master a25c588] amend modify JackyData02
1 file changed, 1 insertion(+), 1 deletion(-)
#最后一次的提交信息被修改
$ git log --pretty=oneline
a25c58804cb3f4045564fc0ec6a4e6eb4dae7072 amend modify JackyData02
cba8800f2daaf4075a506b6d763798ea15ba11cc modify JackyData01
aea0365712908805bc28540b4db9fd2f15360a8b init AddFiles
9.删除项目内容
删除了某一项版本控制下的内容,使用《git add .》无法在索引中删除该文件。
[cpp]
#移除JackyData03文件
$ rm JackyData03
#使用git add . 提示警告,同时调用git status,发现并没有正常提交
$ git add . && git commit -m "remove JackyData03"
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'JackyData03' that are
removed from your working tree are ignored with this version of Git.
* 'git add --ignore-removal <pathspec>', which is the current default,
ignores paths you removed from your working tree.
* 'git add --all <pathspec>' will let you also record the removals.
Run 'git status' to check the paths you removed from your working tree.
# 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: JackyData03
#
no changes added to commit (use "git add" and/or "git commit -a")
[cpp]
#使用git commit -a -m提交删除
$ git commit -a -m "remove JackyData03"
[master c5c83cf] remove JackyData03
1 file changed, 1 deletion(-)
delete mode 100644 JackyData03