赞
踩
$ mkdir learngit
$ cd learngit
$ pwd
/Users/michael/learngit
pwd命令用于显示当前目录。在我的Mac上,这个仓库位于/Users/michael/learngit。
git init
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
git add
$ git add readme.txt
git commit
$ git commit -m "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
-m
后面输入的是本次提交的说明
git status
$ 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: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
git diff
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
Git is free software.
git log
$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0
Author: Michael Liao <askxuefeng@gmail.com>
Date: Tue Aug 20 15:11:49 2013 +0800
append GPL
commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao <askxuefeng@gmail.com>
Date: Tue Aug 20 14:53:12 2013 +0800
add distributed
commit cb926e7ea50ad11b8f9e909c05226233bf755030
Author: Michael Liao <askxuefeng@gmail.com>
Date: Mon Aug 19 17:51:55 2013 +0800
wrote a readme file
git log --pretty=oneline
$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
git reset
$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed
参数 | 含义 |
---|---|
HEAD | 当前版本 |
HEAD^ | 上一版本 |
HEAD^^ | 上上一个版本 |
HEAD~100 | 往上100个版本 |
$ git reset --hard 3628164
HEAD is now at 3628164 append GPL
git reflog
$ git reflog
ea34578 HEAD@{0}: reset: moving to HEAD^
3628164 HEAD@{1}: commit: append GPL
ea34578 HEAD@{2}: commit: add distributed
cb926e7 HEAD@{3}: commit (initial): wrote a readme file
git checkout -- file
$ git checkout -- readme.txt
撤销有两种情况:
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
git rm file
$ rm test.txt
git checkout -b name
$ git checkout -b dev
Switched to a new branch 'dev'
git branch
$ git branch
* dev
master
git checkout name
$ git checkout master
Switched to branch 'master'
git merge name
$ git merge dev
Updating d17efd8..fec145a
Fast-forward
readme.txt | 1 +
1 file changed, 1 insertion(+)
git branch -d name
$ git branch -d dev
Deleted branch dev (was fec145a).
git branch -D name
$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 756d4af).
git update-index --assume-unchanged name
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。