Git study notes

Git study notes (1)

reference :Liao Xuefeng’s blog

1.preparation

First,install the git,open git-bush.Then you will see a window like CMD,which means you are succeed.Now, you can write something in this black window.

2.new a repository

mkdir learngit
cd learngit
pwd    //show you the current content

then you can use git init to initate this respository,making it administrable.like this:

$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/

3.Add a new file to your repository

Till now,we’ve create a repository.Why not add something to it?Put a readme.txt file to the content.Then,write something like this in the git-bush:

$ git add readme.txt(file name)

4.write some notes about your modification

When you finishing adding all the files,you can write something as a comment which will be convenient for you or other readers to know what modifications you’ve made this time.Just like this:

$ git commit -m "wrote a readme file"

then you can see something like this

[master (root-commit) cb926e7] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt

Suppose that we have modified readme.txt,we can use git status order to get the dynamic state about this repository.So you can see:

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

5.get the difference after your modification

But if you went vacation for some days,when you came back,you did’t remember what modification you’ve done to this file,you can use git diff to see the detail.Suppose that the original is
“Git is a distributed version control system.
Git is free software.”
and the second version is
“Git is a distributed version control system.
Git is free software.”
So you can see some sentences like this:

$ 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.

By the way,these words are highlighted in Git-Bush.So I think it will look better.
Before we add this modified file to the respository,we can use git status to see the status(this is a good habit).Now you can see:

 $ git status
 On branch master
 Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

       modified:   readme.txt
`git status` tells us that files to be submitted includes `readme.txt`.

Now,we can submit it:

$ git commit -m "add distributed"
[master ea34578] add distributed
 1 file changed, 1 insertion(+), 1 deletion(-)

At last , we can use git status again. And it says:

 $ git status
 On branch master
nothing to commit (working directory clean)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值