Git 使用筆記

1. 生成git 格式的控制文件

$ mkdir gitproject
$ cd gitproject
[hadoop@localhost gitproject]$ git init
Initialized empty Git repository in /home/hadoop/gitproject/.git/

2. git commit 是指commit的到當前分支

3. 可以切換到任意branch 下打包

    git checkout mybranch

    mvn clean install

 

4. 在commit 之前可以使用diff 查看更改了哪些東西

[hadoop@localhost gitproject]$ vi my.txt
[hadoop@localhost gitproject]$ git add my.txt
[hadoop@localhost gitproject]$ git commit -m "add my.txt"
[master (root-commit) 737950e] add my.txt
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 my.txt
[hadoop@localhost gitproject]$ git diff
[hadoop@localhost gitproject]$
[hadoop@localhost gitproject]$ vi my.txt
[hadoop@localhost gitproject]$ diff my.txt
diff: missing operand after `my.txt'
diff: Try `diff --help' for more information.
[hadoop@localhost gitproject]$ git diff my.txt
diff --git a/my.txt b/my.txt
index 7c87573..42f6c47 100644
--- a/my.txt
+++ b/my.txt
@@ -1 +1,2 @@
 my lover
+really?

5. 如果想丟棄修改,回到當初狀態,可以使用 git stash

$ git diff my.txt
diff --git a/my.txt b/my.txt
index 7c87573..42f6c47 100644
--- a/my.txt
+++ b/my.txt
@@ -1 +1,2 @@
 my lover
+really?
$ git stash
Saved working directory and index state WIP on master: 737950e add my.txt
HEAD is now at 737950e add my.txt
$ cat my.txt
my lover

6. 回到修改狀態

$ cat my.txt
my lover
$ git stash pop
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   my.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (1bfaf437e571ed1201224643ccf58283f20b4265)
$ cat my.txt
my lover
really?

7. 撤掉對某個文件修改

$ cat my.txt
my lover
really?
$ git checkout my.txt
$ cat my.txt
my lover

8. 查看某個文件修改歷史記錄

$ git log my.txt
commit 737950e6e6d3131ddb8d497c0ff3acfac0845258
Author: zilzhang <[email protected]>
Date:   Mon May 12 05:10:59 2014 -0700

    add my.txt

 

9. 如果某個project 進行了變更, 可以把變更存放於某個文件, 如果他人也有一份本地project,他可以通過如下方式自動變更。

    A user: git diff diff_file.txt  ###把變更保存

    B user: git diff apply diff_file.txt  ####把變更也應用於B user的project,這樣可以自動修改相應的內容。好處是A 用戶不用提交, B用戶就可以查看A 變更代碼。

 

10 .git聯機文檔

 git-scm.com/book/zh


 

發佈了40 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章