感謝のプログラミング 10000時間

たどり着いた結果(さき)は、感謝でした。

Introduction of Git

<スポンサーリンク>

英語が苦手。
だから、書くことにした。恥ずかしいけれど、それでも書いていかないと、一生うまくならない。

Tell Git a control space

$ git init
Initialized empty Git repository in /home/sysmgr/demo/.git/

This command "git init" tells Git the directory which is controled by Git.

commiting the change to Git

"git add" command pass on the changes to Git.

$ echo "testing git now" > sample.txt
$ cat sample.txt
testing git now

$ git add sample.txt

"git commit" command means commint the changes to Git.
This ask Git to commit the changes which added to the controled directory.

$ git commit -m "my first commit"
[master (root-commit) 322201a] my first commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 sample.txt

Commiting changes to Git

$ echo "my second test" > sample.txt
$ cat sample.txt
my second test
$ git add sample.txt
$ git commit -m "add second"
[master 0d8396b] add second
 1 files changed, 1 insertions(+), 1 deletions(-)

Check logs of Git

$ git log

If you want to check logs in a compressed way, use "git log --oneline" command.

$ git log --oneline
e15d3f3 added test3
0d8396b add second
322201a my first commit

Compare the history

To compare difference between some version, use the following command.

$ git log --oneline
e15d3f3 added test3
0d8396b add second
322201a my first commit

$ git diff 0d8396b e15d3f3
diff --git a/sample.txt b/sample.txt
index f8971bc..7c27821 100644
--- a/sample.txt
+++ b/sample.txt
@@ -1 +1,2 @@
 my second test
+git test3

"+" means add the line to the text.

How to restore to its original state by Git

$ rm sample.txt
$ cat sample.txt
cat: sample.txt: No such file or directory

$ git log --oneline
e15d3f3 added test3
0d8396b add second
322201a my first commit

$ git checkout e15d3f3 sample.txt
$ cat sample.txt
my second test
git test3

Firstly, use "git log --oneline" command to check the commit ID.
next, use "git checkout [commit ID] [checkout name]"
so, you can get the original file from git.