Git study Note 3

Source: Internet
Author: User
7. instances with multiple branches and merged implementations 1. instances with merged conflicts [root @ localhost ~] # Mkdir-pgitbranche [root @ localhostbranche] # cp-rv... wanyan *. Lazy '... wanyanREADME-'. README '.. wanyanlib-'. lib '.. wanyanlibcomment

 

7. instances that contain multiple branches and merged implementations

1. instances with merged conflicts

[Root @ localhost ~] #Mkdir-P/Git/BraNcHe

[Root @ localhost branche] #Cp-Rv ../wanyan/*. // get lazy.

'../Wanyan/README'-> './README'

'../Wanyan/lib'->'./lib'

'../Wanyan/lib/comment'->'./lib/comment'

'../Wanyan/lib/include'-> './lib/include'

'../Wanyan/lib/include/comment'->'./lib/include/comment'

'../Wanyan/lib/include/main. c'->'./lib/include/main. c'

'../Wanyan/lib/README'-> './lib/README'

[Root @ localhost branche] # git init

InitializEdEmpty Git repository in/git/branche/. git/

[Root @ localhost branche] # gitDd.

[Root @ localhost branche] # git commit-m "1st commit"

[Master (root-commit) e9f37b6] 1st commit

5FileS changed, 9 insertions (+), 0 deletions (-)

Create mode 100644 README

Create mode 100644 lib/README

Create mode 100644 lib/comment

Create mode 100644 lib/include/comment

Create mode 100644 lib/include/main. c

[Root @ localhost branche] #Cat. Git/HEAD

Ref: refs/heads/master

[Root @ localhost branche] # cat. git/refs/heads/master

E9f37b62445a7c855da-cb00455c9922ea356c29

[Root @ localhost branche] # git cat-file-t e9f3

Commit

First Change:

[Root @ localhost branche] # vi lib/comment

 

Include

Change

The last change

[Root @ localhost branche] # git commit-a-m "2rd commit"

[Master c2a876e] 2rd commit

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

The second change:

[Root @ localhost branche] # vi README

 

Just test!

Another hang!

Last hang

[Root @ localhost branche] # git commit-a-m "3rd commit"

[Master f5febf9] 3rd commit

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

Create Branch

[Root @ localhost branche] # git branch laji

[Root @ localhost branche] # ll. git/refs/heads/

Total 16

-Rw-r -- 1 root 41 Nov 27 05:19 laji

-Rw-r -- 1 root 41 Nov 27 05:18 master

[Root @ localhost branche] # cat. git/refs/heads/laji // the following code points to the same commit

F5febf9e98c5dc2a1279a56c47642677fdea79ec

[Root @ localhost branche] # cat. git/refs/heads/master

F5febf9e98c5dc2a1279a56c47642677fdea79ec

[Root @ localhost branche] # git branch // view the current branch

Laji

* Master

[Root @ localhost branche] # git checkout laji // switch Branch

Switched to branch 'laji'

[Root @ localhost branche] # git branch

* Laji

Master

[Root @ localhost branche] # cat. git/HEAD

Ref: refs/heads/laji

Next we will demonstrate the relationship between branches (independent of each other). Modifications under the Branch laji have no effect on the master branch.

First, modify it under the laji branch.

[Root @ localhost branche] # vi README

Just test!

Another hang!

Last hang

Change for branch

[Root @ localhost branche] # git commit-a-m "laji 4th commit"

[Laji b72a123] laji 4th commit

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

[Root @ localhost branche] # cat README

Just test!

Another hang!

Last hang

Change for branch

[Root @ localhost branche] # cat. git/refs/heads/laji // commit is different. It can be seen that a branch appears.

B72a1238f9962dd103c5839077026e7c342595ce

[Root @ localhost branche] # cat. git/refs/heads/master

F5febf9e98c5dc2a1279a56c47642677fdea79ec

Switch to the master branch.

[Root @ localhost branche] # git checkout master

Switched to branch 'master'

[Root @ localhost branche] # git branch

Laji

* Master

[Root @ localhost branche] # cat README

Just test!

Another hang!

Last hang

Then create a fork (that is, to make further git For mater)

[Root @ localhost branche] # git branch

Laji

* Master

[Root @ localhost branche] # vi README

 

Just test!

Another hang!

Last hang

The master change

[Root @ localhost branche] # git commit-a-m "master 4th commit"

[Master bf7bf97] master 4th commit

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

[Root @ localhost branche] # cat README // compares the list with the laji Branch

Just test!

Another hang!

Last hang

The master change

[Root @ localhost branche] # git checkout laji

Switched to branch 'laji'

[Root @ localhost branche] # cat README

Just test!

Another hang!

Last hang

Change for branch

Finally, merge the branches (merge laji to the master). This merge can be performed between different files (because it is difficult to do the same work in cooperative development projects)

[Root @ localhost branche] # git branch

Laji

* Master

[Root @ localhost branche] # git merge laji

Auto-merging README

CONFLICT (content): Merge conflict in README

Automatic merge failed; fix conflicts and then commit the reSuLt.

[Root @ localhost branche] # cat README // conflict occurs when a file is merged.

Just test!

Another hang!

Last hang

<HEAD

The master change

========

Change for branch

>>>>>>> Laji

[Root @ localhost branche] # git branch

Laji

* Master

[Root @ localhost branche] # vi README

 

Just test!

Another hang!

Last hang

The master change

Change for branch

~

[Root @ localhost branche] # git add.

[Root @ localhost branche] # git commit "last commit"

In this way, the conflict is resolved and the submission is successful.

[Root @ localhost branche] # git branch-D laji // Delete useless branches

Deleted branch laji (was b72a123 ).

2. No conflicting instances

[Root @ localhost other] #Cd..

[Root @ localhost git] # mkdir another

[Root @ localhost git] # cd another/

[Root @ localhost another] # vi a1

 

Wanyan

~

[Root @ localhost another] # vi a2

 

Ethnicity

[Root @ localhost another] # git init

Initialized empty Git repository in/git/another/. git/

[Root @ localhost another] # git add.

[Root @ localhost another] # git commit-m "1st commit"

[Master (root-commit) f723f47] 1st commit

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

Create mode 100644 a1

Create mode 100644 a2

[Root @ localhost another] # git branch laji

[Root @ localhost another] # git branch

Laji

* Master

[Root @ localhost another] # git checkout laji

Switched to branch 'laji'

[Root @ localhost another] # vi a1

 

Wanyan

Zhengjing

[Root @ localhost another] # git commit-a-m "laji 2nd commit"

[Laji 05cda63] laji 2nd commit

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

[Root @ localhost another] # git checkout master

[Root @ localhost another] # vi a2

 

Ethnicity

Beta

[Root @ localhost another] # git commit-a-m "mater 3rd commit"

[Master 1239b8e] mater 3rd commit

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

[Root @ localhost another] # cat a1

Wanyan

[Root @ localhost another] # cat a2

Ethnicity

Beta

[Root @ localhost another] # git checkout laji

Switched to branch 'laji'

[Root @ localhost another] # cat a1

Wanyan

Zhengjing

[Root @ localhost another] # cat a2

Ethnicity

[Root @ localhost another] # git checkout master

Switched to branch 'master'

[Root @ localhost another] # git merge laji

Merge made by the 'cursive'sTrAtegy.

A1 | 1 +

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

[Root @ localhost another] # cat a1

Wanyan

Zhengjing

[Root @ localhost another] # cat a2

Ethnicity

Beta

[Root @ localhost another] # git branch-D laji // Delete branch

Deleted branch laji (was 05cda63 ).

[Root @ localhost another] # git branch

* Master

 

Eighth: Merge instances with only one branch

[Root @ localhost git] # mkdir other

[Root @ localhost git] # cd other/

[Root @ localhost other] # vim main

Hello ethnicitybeta

[Root @ localhost other] # git init

Initialized empty Git repository in/git/other/. git/

[Root @ localhost other] # git add.

[Root @ localhost other] # git commit-m'1st commit'

[Master (root-commit) 9ef10c3] 1st commit

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

Create mode 100644 main

[Root @ localhost other] # git branch wanyan

[Root @ localhost other] # git checkout wanyan

Switched to branch 'wanyan'

[Root @ localhost other] # git branch

Master

* Wanyan

[Root @ localhost other] # vi main

 

Hello ethnicitybeta

Wanyanzhenjiang

~

[Root @ localhost other] # git commit-a-m "wanyan 2nd commit"

[Wanyan 96aa677] wanyan 2nd commit

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

[Root @ localhost other] # cat main

Hello ethnicitybeta

Wanyanzhenjiang

[Root @ localhost other] # git checkout master

Switched to branch 'master'

[Root @ localhost other] # git branch

* Master

Wanyan

[Root @ localhost other] # cat main

Hello ethnicitybeta

[Root @ localhost other] # git checkout master

Switched to branch 'master'

[Root @ localhost other] # git merge wanyan

Updating 9ef10c3 .. 96aa677

Fast-forward // indicates that the merged branch does not have forks.

Main | 1 +

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

[Root @ localhost other] # cat main

Hello ethnicitybeta

Wanyanzhenjiang

 

 

Lab ended

 

Conclusion: The concept of version control has been put into use before. The only concept of the term is svn, which has not been studied yet. It is very easy to use with git, here is a systematic learning record for use at work. I would like to thank Mr. Xiao Bu for his selfless teaching.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.