求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Modeler   Code  
会员   
 
  
 
 
 
   
分享到
Git: Basics
 

作者:郝一二三;发布于2013-2-25

 

"Some Git operating log for rookie , hope useful to you :-)"

--------------------------------------------------------------------------------

Add a file.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git init

Reinitialized existing Git repository in /home/jesse123/1_gitAddNode/.git/

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls -a

. .. .git

jesse123@BJSCWL1802 ~/1_gitAddNode

$ touch main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ echo "Hello world." >> main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ cat main.txt

Hello world.

jesse123@BJSCWL1802 ~/1_gitAddNode    // 同步至缓冲区

$ git add main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode    // 提交到仓库(本地)

$ git commit -m "Add a file."

[master (root-commit) 274c5d5] Add a file.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 main.txt

--------------------------------------------------------------------------------

Make some change.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ echo "Make some changes." >> main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ cat main.txt

Hello world.

Make some changes.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status -s

M main.txt    // M(red) 表示工作区有修改

jesse123@BJSCWL1802 ~/1_gitAddNode

$ 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: main.txt

#

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------

Commit change.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git add main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status -s

M main.txt      // M(green)表示缓冲区已准备好,可以提交

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status

# On branch master

# Changes to be committed:

# (use "git reset HEAD <file>..." to unstage)

#

# modified: main.txt

#

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git commit -m "Make some changes."

[master 70519d0] Make some changes.

1 files changed, 1 insertions(+), 0 deletions(-)

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status -s

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status

# On branch master

nothing to commit (working directory clean)

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git log

commit 70519d08e8b251a44698c7aabdcaf9e79c4b1f57

Author: Jie HAO <jie.hao-x-ext@gmail.com>

Date: Sat Feb 16 11:27:10 2013 +0800

Make some changes.

commit 274c5d567af06c67532a306a51fee260e28acd7c

Author: Jie HAO <jie.hao-x-ext@gmail.com>

Date: Sat Feb 16 11:07:43 2013 +0800

Add a file.

--------------------------------------------------------------------------------

Add new file.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ touch forNode3_master.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status -s

?? forNode3_master.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git add forNode3_master.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git status -s

A forNode3_master.txt    // A(green)表示工作区 添加新文件(之前为有记录)

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git ls-files

forNode3_master.txt

main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git commit -m "Add new forNode3_master.txt."

[master 766b6f5] Add new forNode3_master.txt.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 forNode3_master.txt

--------------------------------------------------------------------------------

Make new branch.

$ git log --pretty=oneline

766b6f563184380d5e794522d79ef6a008533d21 Add new forNode3_master.txt.

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git reset --hard 70519

HEAD is now at 70519d0 Make some changes.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git log --pretty=oneline

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git checkout -b branchFrom_2        // 在当前节点创建新分支

Switched to a new branch 'branchFrom_2'

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -v

* branchFrom_2 70519d0 Make some changes.

master 70519d0 Make some changes.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ touch file_branchFrom_2.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git add file_branchFrom_2.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git commit -m "Add node 4."

[branchFrom_2 4ddf4c4] Add node 4.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 file_branchFrom_2.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git log --pretty=oneline

4ddf4c4cf7e6fc77eff476d9e8d45058153b1595 Add node 4.

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

--------------------------------------------------------------------------------

Make another new branch.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git log --pretty=oneline

4ddf4c4cf7e6fc77eff476d9e8d45058153b1595 Add node 4.

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -v

* branchFrom_2 4ddf4c4 Add node 4.

master 766b6f5 Add new forNode3_master.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git checkout 70519 -b branchFrom_2_forNode5

Switched to a new branch 'branchFrom_2_forNode5'

jesse123@BJSCWL1802 ~/1_gitAddNode

$ touch file_branchFrom_2_forNode5.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git add file_branchFrom_2_forNode5.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git commit -m "Add node5."

[branchFrom_2_forNode5 31ef565] Add node5.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 file_branchFrom_2_forNode5.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -v

branchFrom_2 4ddf4c4 Add node 4.

* branchFrom_2_forNode5 31ef565 Add node5.

master 766b6f5 Add new forNode3_master.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

file_branchFrom_2_forNode5.txt main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git checkout branchFrom_2

Switched to branch 'branchFrom_2'

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

file_branchFrom_2.txt main.txt

--------------------------------------------------------------------------------

Rm old branch.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git checkout master

Switched to branch 'master'

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git reset --hard 766b6

HEAD is now at 766b6f5 Add new forNode3_master.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -v

branchFrom_2 4ddf4c4 Add node 4.

branchFrom_2_forNode5 31ef565 Add node5.

* master 766b6f5 Add new forNode3_master.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -d branchFrom_2_forNode5

error: The branch 'branchFrom_2_forNode5' is not fully merged.

If you are sure you want to delete it, run 'git branch -D branchFrom_2_forNode5'.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -D branchFrom_2_forNode5

Deleted branch branchFrom_2_forNode5 (was 31ef565).

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git branch -v

branchFrom_2 4ddf4c4 Add node 4.

* master 766b6f5 Add new forNode3_master.txt.

--------------------------------------------------------------------------------

Add Tag.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git tag -m "Say bye-bye to all previous practice." old_practice

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git rev-parse refs/tags/old_practice

a49680369aacbaf64557d3a83c1f21aca1224fa5

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git cat-file -p refs/tags/old_practice

object 766b6f563184380d5e794522d79ef6a008533d21

type commit

tag old_practice

tagger Jie HAO <jie.hao-x-ext@gmail.com> Sat Feb 16 15:36:35 2013 +0800

Say bye-bye to all previous practice.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git describe

old_practice

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

forNode3_master.txt main.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ touch onePice.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ echo "Hello, new world." >> onePice.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ cat onePice.txt

Hello, new world.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git add onePice.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git commit -m "Hello, add onePice.txt."

[master 5611a82] Hello, add onePice.txt.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 onePice.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git reset --hard old_practice    // tag 取代 hash值的好处 显而易见

HEAD is now at 766b6f5 Add new forNode3_master.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

forNode3_master.txt main.txt

--------------------------------------------------------------------------------

Diff between Tags.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git reset --hard 5611a82

HEAD is now at 5611a82 Hello, add onePice.txt.

jesse123@BJSCWL1802 ~/1_gitAddNode

$ ls

forNode3_master.txt main.txt onePice.txt

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git tag -m "Add onePice.txt." one_pice

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git describe

one_pice

jesse123@BJSCWL1802 ~/1_gitAddNode

$ git diff old_practice one_pice

diff --git a/onePice.txt b/onePice.txt

new file mode 100644

index 0000000..a8d301a

--- /dev/null

+++ b/onePice.txt

@@ -0,0 +1 @@

+Hello, new world.

--------------------------------------------------------------------------------

Create repository.

jesse123@BJSCWL1802 ~    // 将当前进度打包成仓库,供他人分享

$ git clone --bare /home/jesse123/1_gitAddNode/ /home/jesse123/share/shared.git

Cloning into bare repository '/home/jesse123/share/shared.git'...

done.

jesse123@BJSCWL1802 ~

$ git clone file:///home/jesse123/share/shared.git user2

Cloning into 'user2'...

remote: Counting objects: 16, done.

remote: Compressing objects: 100% (10/10), done.

remote: Total 16 (delta 2), reused 0 (delta 0)

Receiving objects: 100% (16/16), done.

Resolving deltas: 100% (2/2), done.

jesse123@BJSCWL1802 ~

$ ls

1_gitAddNode share user2

jesse123@BJSCWL1802 ~

$ cd user2/

jesse123@BJSCWL1802 ~/user2

$ ls

forNode3_master.txt main.txt onePice.txt

jesse123@BJSCWL1802 ~/user2

$ git config user.name user2

jesse123@BJSCWL1802 ~/user2

$ git config user.email

jesse123@BJSCWL1802 ~/user2

$ git log --pretty=oneline

5611a829225e22f250e1679e20b5e6a9fa2d8a7c Hello, add onePice.txt.

766b6f563184380d5e794522d79ef6a008533d21 Add new forNode3_master.txt.

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

--------------------------------------------------------------------------------

Conflict!

jesse123@BJSCWL1802 ~/user1

$ ls

forNode3_master.txt main.txt onePice.txt

jesse123@BJSCWL1802 ~/user1

$ mkdir team

jesse123@BJSCWL1802 ~/user1

$ echo "I'm user1." > team/user1.txt

jesse123@BJSCWL1802 ~/user1

$ git add team/

jesse123@BJSCWL1802 ~/user1

$ git commit -m "user1's profile."

[master 4472c99] user1's profile.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/user1.txt

jesse123@BJSCWL1802 ~/user1

$ git push

Counting objects: 5, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (4/4), 318 bytes, done.

Total 4 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (4/4), done.

To file:///home/jesse123/share/shared.git

5611a82..4472c99 master -> master

jesse123@BJSCWL1802 ~/user1

$ git log --pretty=oneline

4472c9932774aaa9f1b1f23adc6b2401f1fc6006 user1's profile.

5611a829225e22f250e1679e20b5e6a9fa2d8a7c Hello, add onePice.txt.

766b6f563184380d5e794522d79ef6a008533d21 Add new forNode3_master.txt.

70519d08e8b251a44698c7aabdcaf9e79c4b1f57 Make some changes.

274c5d567af06c67532a306a51fee260e28acd7c Add a file.

jesse123@BJSCWL1802 ~/user2

$ mkdir team

jesse123@BJSCWL1802 ~/user2

$ echo "I'm user2." > team/user2.txt

jesse123@BJSCWL1802 ~/user2

$ git add team/

jesse123@BJSCWL1802 ~/user2

$ git commit -m "user2's profile."

[master d2c134c] user2's profile.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/user2.txt

jesse123@BJSCWL1802 ~/user2

$ git push

To file:///home/jesse123/share/shared.git

! [rejected] master -> master (non-fast-forward)    // 因为冲突,不能 fast-forward

error: failed to push some refs to 'file:///home/jesse123/share/shared.git'

To prevent you from losing history, non-fast-forward updates were rejected

Merge the remote changes (e.g. 'git pull') before pushing again. See the

'Note about fast-forwards' section of 'git push --help' for details.

Why?

jesse123@BJSCWL1802 ~/user1

$ git rev-list HEAD

4472c9932774aaa9f1b1f23adc6b2401f1fc6006

5611a829225e22f250e1679e20b5e6a9fa2d8a7c

766b6f563184380d5e794522d79ef6a008533d21

70519d08e8b251a44698c7aabdcaf9e79c4b1f57

274c5d567af06c67532a306a51fee260e28acd7c

jesse123@BJSCWL1802 ~/user1

$ git ls-remote origin

4472c9932774aaa9f1b1f23adc6b2401f1fc6006 HEAD

4ddf4c4cf7e6fc77eff476d9e8d45058153b1595 refs/heads/branchFrom_2

4472c9932774aaa9f1b1f23adc6b2401f1fc6006 refs/heads/master

a49680369aacbaf64557d3a83c1f21aca1224fa5 refs/tags/old_practice

766b6f563184380d5e794522d79ef6a008533d21 refs/tags/old_practice^{}

0ed85278d7ac258912a81ba37a55c634f1967640 refs/tags/one_pice

5611a829225e22f250e1679e20b5e6a9fa2d8a7c refs/tags/one_pice^{}

jesse123@BJSCWL1802 ~/user2

$ git rev-list HEAD

d2c134cc9c83d85699f0ec443af7e49fbf5433ac  // 这里与user1已不同

5611a829225e22f250e1679e20b5e6a9fa2d8a7c

766b6f563184380d5e794522d79ef6a008533d21

70519d08e8b251a44698c7aabdcaf9e79c4b1f57

274c5d567af06c67532a306a51fee260e28acd7c

jesse123@BJSCWL1802 ~/user2

$ git ls-remote origin

4472c9932774aaa9f1b1f23adc6b2401f1fc6006 HEAD

4ddf4c4cf7e6fc77eff476d9e8d45058153b1595 refs/heads/branchFrom_2

4472c9932774aaa9f1b1f23adc6b2401f1fc6006 refs/heads/master

a49680369aacbaf64557d3a83c1f21aca1224fa5 refs/tags/old_practice

766b6f563184380d5e794522d79ef6a008533d21 refs/tags/old_practice^{}

0ed85278d7ac258912a81ba37a55c634f1967640 refs/tags/one_pice

5611a829225e22f250e1679e20b5e6a9fa2d8a7c refs/tags/one_pice^{}

--------------------------------------------------------------------------------

Merge made by recursive.

jesse123@BJSCWL1802 ~/user2

$ git pull

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 4 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (4/4), done.

From file:///home/jesse123/share/shared

5611a82..4472c99 master -> origin/master

Merge made by the 'recursive' strategy.

team/user1.txt | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/user1.txt

jesse123@BJSCWL1802 ~/user2

$ ls

forNode3_master.txt main.txt onePice.txt team

jesse123@BJSCWL1802 ~/user2

$ ls ./team/

user1.txt user2.txt

jesse123@BJSCWL1802 ~/user2

$ git log --graph --oneline

* 7926606 Merge branch 'master' of file:///home/jesse123/share/shared

|\

| * 4472c99 user1's profile.

* | d2c134c user2's profile.

|/

* 5611a82 Hello, add onePice.txt.

* 766b6f5 Add new forNode3_master.txt.

* 70519d0 Make some changes.

* 274c5d5 Add a file.

jesse123@BJSCWL1802 ~/user2

$ git push

Counting objects: 10, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (5/5), done

Writing objects: 100% (7/7), 652 bytes, done.

Total 7 (delta 2), reused 0 (delta 0)

Unpacking objects: 100% (7/7), done.

To file:///home/jesse123/share/shared.git

4472c99..7926606 master -> master

--------------------------------------------------------------------------------

Changes in different files.

jesse123@BJSCWL1802 ~/user1

$ git fetch

remote: Counting objects: 10, done.

remote: Compressing objects: 100% (5/5), done.

remote: Total 7 (delta 2), reused 0 (delta 0)

Unpacking objects: 100% (7/7), done.

From file:///home/jesse123/share/shared

4472c99..7926606 master -> origin/master

jesse123@BJSCWL1802 ~/user1

$ git ls-files

forNode3_master.txt

main.txt

onePice.txt

team/user1.txt

jesse123@BJSCWL1802 ~/user1

$ git merge origin/master

Updating 4472c99..7926606

Fast-forward

team/user2.txt | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/user2.txt

jesse123@BJSCWL1802 ~/user1

$ ls ./team/

user1.txt user2.txt

--------------------------------------------------------------------------------

Changes in same file.

jesse123@BJSCWL1802 ~/user2/team

$ echo "user2 --> hello." > share.txt

jesse123@BJSCWL1802 ~/user2/team

$ git add share.txt

jesse123@BJSCWL1802 ~/user2/team

$ git commit -m "share.txt change by user2."

[master ad972c0] share.txt change by user2.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/share.txt

jesse123@BJSCWL1802 ~/user2/team

$ git push

Counting objects: 6, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (4/4), 379 bytes, done.

Total 4 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (4/4), done.

To file:///home/jesse123/share/shared.git

7926606..ad972c0 master -> master

jesse123@BJSCWL1802 ~/user1/team

$ echo "user1 --> hi." > share.txt

jesse123@BJSCWL1802 ~/user1/team

$ git add -u

jesse123@BJSCWL1802 ~/user1/team

$ git commit -m "share.txt change by user1."

[master e374ea5] share.txt change by user1.

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 team/share.txt

jesse123@BJSCWL1802 ~/user1/team    // 先获取远程分支现状

$ git fetch

jesse123@BJSCWL1802 ~/user1/team    // 再对比,查看与本地分支的区别

$ git diff master origin/master

diff --git a/team/share.txt b/team/share.txt

index 466ac60..bcb5df9 100644

--- a/team/share.txt

+++ b/team/share.txt

@@ -1 +1,2 @@

user1 --> hi.

+user2 --> hello.

jesse123@BJSCWL1802 ~/user1/team    // 最后合并

$ git merge origin/master

Updating e374ea5..449cb76

Fast-forward

team/share.txt | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)

jesse123@BJSCWL1802 ~/user1/team

$ cat share.txt

user1 --> hi.

user2 --> hello.

Solve conflict and “git blame”

jesse123@BJSCWL1802 ~/user1/team

$ git blame share.txt       // 查看内容具体由谁改动,神器!

e374ea55 (user1 2013-02-17 14:30:39 +0800 1) user1 --> hi.

ad972c01 (user2 2013-02-17 14:30:03 +0800 2) user2 --> hello.

-------------------------------------------------------------------------------

Add your remote branch.

jesse123@BJSCWL1802 ~

$ git clone file:///home/jesse123/share/shared.git/ user3

Cloning into 'user3'...

remote: Counting objects: 39, done.

remote: Compressing objects: 100% (26/26), done.

remote: Total 39 (delta 8), reused 0 (delta 0)

Receiving objects: 100% (39/39), done.

Resolving deltas: 100% (8/8), done.

jesse123@BJSCWL1802 ~/user3

$ git log --pretty=oneline –graph -2

* 449cb767af7a4064b8f35ca4ab6c185cda4f8453 Solve conflict in share.txt.

|\

| * ad972c01d1cf7225109ed2bc66dee042e3759731 share.txt change by user2.

jesse123@BJSCWL1802 ~/user3

$ git show-ref

449cb767af7a4064b8f35ca4ab6c185cda4f8453 refs/heads/master

449cb767af7a4064b8f35ca4ab6c185cda4f8453 refs/remotes/origin/HEAD

4ddf4c4cf7e6fc77eff476d9e8d45058153b1595 refs/remotes/origin/branchFrom_2

449cb767af7a4064b8f35ca4ab6c185cda4f8453 refs/remotes/origin/master

a49680369aacbaf64557d3a83c1f21aca1224fa5 refs/tags/old_practice

0ed85278d7ac258912a81ba37a55c634f1967640 refs/tags/one_pice

jesse123@BJSCWL1802 ~/user3

$ git checkout user3LocalBranch

Switched to a new branch 'user3LocalBranch'

jesse123@BJSCWL1802 ~/user3

$ git branch -v

master 449cb76 [behind 3] Solve conflict in share.txt.

* user3LocalBranch 449cb76 Solve conflict in share.txt.

jesse123@BJSCWL1802 ~/user3

$ git push origin user3LocalBranch:user3RomoteBranch    // 本地分支 推送到 指定远程分支

Total 0 (delta 0), reused 0 (delta 0)

To file:///home/jesse123/share/shared.git/

* [new branch] user3LocalBranch -> user3RomoteBranch

jesse123@BJSCWL1802 ~/share/shared.git

$ git branch -v

branchFrom_2 4ddf4c4 Add node 4.

* master 449cb76 Solve conflict in share.txt.

old_master 449cb76 Solve conflict in share.txt.

user3RomoteBranch 449cb76 Solve conflict in share.txt.

--------------------------------------------------------------------------------

Add file in User3’s branch.

jesse123@BJSCWL1802 ~/user3

$ touch user3.txt

jesse123@BJSCWL1802 ~/user3

$ git add user3.txt

jesse123@BJSCWL1802 ~/user3

$ git commit -m "Add user3.txt in user3LocalBranch."

[user3LocalBranch 7cec762] Add user3.txt in user3LocalBranch.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 user3.txt

jesse123@BJSCWL1802 ~/user3

$ git push

Everything up-to-date

jesse123@BJSCWL1802 ~/user3

$ git push origin user3LocalBranch:user3RemoteBranch

Counting objects: 3, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 290 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (2/2), done.

To file:///home/jesse123/share/shared.git/

449cb76..7cec762 user3LocalBranch -> user3RemoteBranch

--------------------------------------------------------------------------------

Add your remote branch.

jesse123@BJSCWL1802 ~/user1

$ touch node8_master.txt

jesse123@BJSCWL1802 ~/user1

$ git add node8_master.txt

jesse123@BJSCWL1802 ~/user1

$ git commit -m "Create node8_master.txt."

[master f1efb8c] Create node8_master.txt.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 node8_master.txt

jesse123@BJSCWL1802 ~/user1

$ git push

Counting objects: 3, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 239 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (2/2), done.

To file:///home/jesse123/share/shared.git

449cb76..f1efb8c master -> master

jesse123@BJSCWL1802 ~/user1

$ git merge origin/master origin/user3RemoteBranch    // “特性分支”的合并

Already up-to-date with origin/master

Trying simple merge with origin/user3RemoteBranch

Merge made by the 'octopus' strategy.

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 user3.txt

jesse123@BJSCWL1802 ~/user1

$ git push

Counting objects: 4, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 298 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (2/2), done.

To file:///home/jesse123/share/shared.git

f1efb8c..05a04b0 master -> master

jesse123@BJSCWL1802 ~/share/shared.git

$ git log --pretty=oneline --graph -3

* 05a04b01b9caf0b41931de337b87aaebc7bc7367 Merge remote-tracking branches 'origin/master' and 'origin/user3RemoteBranch'

|\

| * 7cec762a9eda398290b26cdbfd61d55acc69f195 Add user3.txt in user3LocalBranch.

* | f1efb8c3edab080d021c6c8a2874f435d6155f29 Create node8_master.txt.

--------------------------------------------------------------------------------

Add your remote branch.

jesse123@BJSCWL1802 ~/user3

$ git branch -r

origin/HEAD -> origin/master

origin/branchFrom_2

origin/master

origin/user3RemoteBranch

jesse123@BJSCWL1802 ~/user3

$ git checkout -b branchFrom_2 origin/branchFrom_2    // 获取远程分支,建立对应的本地分支

Branch branchFrom_2 set up to track remote branch branchFrom_2 from origin.

Switched to a new branch 'branchFrom_2'

jesse123@BJSCWL1802 ~/user3

$ ls

file_branchFrom_2.txt main.txt

jesse123@BJSCWL1802 ~/user3

$ git branch -v

* branchFrom_2 4ddf4c4 Add node 4.

master 05a04b0 Merge remote-tracking branches 'origin/master' and 'origin/user3RemoteBranch'

user3LocalBranch 7cec762 Add user3.txt in user3LocalBranch.

jesse123@BJSCWL1802 ~/user3

$ git rebase master      // 特性分支的更新

First, rewinding head to replay your work on top of it...

Applying: Add node 4.

jesse123@BJSCWL1802 ~/user3

$ ls

file_branchFrom_2.txt main.txt onePice.txt user3.txt

forNode3_master.txt node8_master.txt team


   


软件配置管理的问题、目的
软件配置管理规范
CQWeb 7.1性能测试与调优指南
为什么需要使用ClearCase
ClearCase与RTC的集成
利用ClearQuest 进行测试管理
更多...   


产品发布管理
配置管理方法、实践、工具
多层次集成配置管理
使用CC与CQ进行项目实践
CVS与配置管理
Subversion管理员


配置管理实践(从组织级到项目级)
通号院 配置管理规范与应用
配置管理日构建及持续集成
丹佛斯 ClearCase与配置管理
中国移动 软件配置管理
中国银行 软件配置管理
天津华翼蓝天科技 配置管理与Pvcs