git 學習筆記

學習git筆記(work 中包含 text)git

 

建立目錄學習

work $ mkdir text3d

 

跳轉到某一目錄下code

work $ cd text ci

 

查看目錄it

text $ pwdio

 

work/texttable

 

把這個目錄變成Git能夠管理的倉庫ast

wrok $ git inittest

Initialized empty Git repository in /work/text/.git/  //告訴你是一個空的倉庫(empty Git repository)

 

告訴Git,把文件添加到倉庫

work $ git add text

 

告訴Git,把文件提交到倉庫-m後面輸入的是本次提交的說明

work $ git commit -m ‘ci'

[master 9727e82] ci

 1 file changed, 2 insertions(+), 20 deletions(-)

 rewrite src/test.txt (91%)

爲何Git添加文件須要addcommit一共兩步呢?由於commit能夠一次提交不少文件,因此你能夠屢次add不一樣的文件,好比:

$ git add file1.txt
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."

 

掌握倉庫當前的狀態

work $ 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")

 

查看修改內容 在add 以前的修改

work $ git diff test 

 

diff --git a/src/test.txt b/src/test.txt

index 99e0e11..013b5bc 100644

--- a/src/test.txt

+++ b/src/test.txt

@@ -1,2 +1,2 @@

 Git is a distributed version control system.

-Git is free software distributed under the GPL.

\ No newline at end of file

+Git is free software.

\ No newline at end of file

 

查看歷史記錄

work $ git log

 

 

 

 

commit 3d131e0e59e87a42e80c850afd91e9c745340b62

Author: jiayin.zhang <jiayin.zhang@asiainnovations.com>

Date:   Fri Aug 26 12:06:00 2016 +0800

 

    ci

 

commit 443d881f13eff791822fe1945186e2654ccf1dc6

Author: jiayin.zhang <jiayin.zhang@asiainnovations.com>

Date:   Fri Aug 26 11:55:53 2016 +0800

 

    ci

 

commit 9727e82838c568cafd12a82da68851b33a205507

Author: jiayin.zhang <jiayin.zhang@asiainnovations.com>

Date:   Fri Aug 26 11:43:55 2016 +0800

 

    ci

 

若是嫌輸出信息太多,看得眼花繚亂的,能夠試試加上--pretty=oneline參數

work $ git log --pretty=oneline

 

 

3d131e0e59e87a42e80c850afd91e9c745340b62 ci

443d881f13eff791822fe1945186e2654ccf1dc6 ci

9727e82838c568cafd12a82da68851b33a205507 ci

 

回退到上一個版本  上一個版本就是HEAD^,上上一個版本就是HEAD^^,固然往上100個版本寫100個^比較容易數不過來,因此寫成HEAD~100

work $ git reset --hard HEAD^

HEAD is now at 443d881 ci

 

因而就能夠指定回到將來的某個版本

work $ git reset --hard 3d131e0

 

HEAD is now at 3d131e0 ci

 

 

每一次命令

$ git reflog

 

3d131e0 HEAD@{0}: reset: moving to 3d131e0

443d881 HEAD@{1}: reset: moving to HEAD^

3d131e0 HEAD@{2}: commit: ci

443d881 HEAD@{3}: commit: ci

9727e82 HEAD@{4}: commit: ci

 

查看文件內容

$ cat test.txt

 

Git is a distributed version control system.

Git is free software distributed under the GPL.

Git has a mutable index called stage.

Git tracks changes.%

 

查看工做區和版本庫裏面最新版本的區別

$ git diff HEAD -- readme.txt 

 

 

iff --git a/src/test.txt b/src/test.txt

index 9a8b341..930b096 100644

--- a/src/test.txt

+++ b/src/test.txt

@@ -1,4 +1,3 @@

 Git is a distributed version control system.

 Git is free software distributed under the GPL.

-Git has a mutable index called stage.

-Git tracks changes of files.

\ No newline at end of file

+Git has a mutable index call

\ No newline at end of file

 

備用

備用

相關文章
相關標籤/搜索