Git study notes

来源:互联网 发布:java获取jar包中文件 编辑:程序博客网 时间:2024/06/02 06:12

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 learngitcd learngitpwd    //show you the current content

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

$ git initInitialized 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 statusOn branch masterChanges 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.txtno 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.txtindex 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 masternothing to commit (working directory clean)
0 0
原创粉丝点击