Git Learning (ii)

Source: Internet
Author: User
Tags tagname version control system

Remote Warehouse

Git is a distributed version control system, and the same git repository can be distributed across different machines.

At the earliest, there was only one machine on the original version, since then, the other machine can "clone" the original repository, and each machine disease has no primary and secondary points, in fact, a machine as long as it is not in the same directory, but also can clone multiple repositories, but it doesn't make sense.


GitHub

As a server, everyone else clones a copy from this "server" repository to their own computer, and each pushes their commits to the server repository, and pulls someone else's submission from the server repository.

The transfer between your local repository git and GitHub repositories is encrypted via SSH


To add a remote library

Now that you have created a git repository locally, you want to create a git repository on GitHub and have the two warehouses remotely synchronized.

1. Login to GitHub to create a new warehouse "repository"

2, in Repository name fill in the warehouse name (assuming Learngit), the other remains the default, the successful creation of a new Git repository

3. You can now associate an existing local repository with this warehouse and then push the contents of the local repository onto GitHub

git remote add origin [email protected]:chehlling/learngit.git where chehlling is my GitHub account name

4. Push all the contents of the local library to the remote library

git push-u Origin master pushes the current branch master to the remote plus-u option because the remote library is empty the first time The master branch is pushed. Git will not only push the local master branch to the remote Master Branch, but also associate the local Master branch and the remote.

From now on, you can push your local branch's latest changes to GitHub via git push origin master


Cloning from a remote library

git clone [email protected]:chehlling/chatd

To clone a warehouse, you must know the warehouse address

When cloning from a remote repository, git actually automatically corresponds to the local master branch and the remote Master Branch, and the default name of the remote Repository is Origin

Git remote

Git remote-v


Branch Management

View branches:git branch

Create a branch:git branch name

Switch branches:git checkout name

Create + Switch branch:git checkout-name

Merge a branch to the current branch :git merge name

Delete branch:git branch-d name

View Branch Merge diagram:git log--graph


Each time a version is submitted, the master branch moves forward, and Git strings the versions into a timeline, which is a branch of the line.

When there is only one time line, this branch is called the main branch, the Master branch.

Head points to Master,master and points to commits, so head points to the current branch.


When a new branch is created, Git creates a new pointer, pointing to the same commit as Master

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/89/34/wKiom1gLdjyw2I2eAAAW_U8JRCI147.png "title=" Git_ Head_master. PNG "alt=" Wkiom1gldjyw2i2eaaaw_u8jrci147.png "/>


Branch conflict

View conflicts by viewing the contents of a file directly

You can manually modify the file before committing


Branch Management

Often when merging branches, GIT uses fast forward mode when it is possible , in which case the branch information is discarded after the branch is deleted, that is, the merge cannot be seen once.

Adding the--NO-FF parameter can prohibit the use of Fast forward mode, the merged history has branches, can be seen to have been merged.


In the actual development, the master branch should be very stable, only to release the new version, usually do not work on it;

The Dev branch is unstable, and at some point, the Dev branch is merged to master;

Everyone works on the dev branch, and sometimes merges on the dev branch.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/89/31/wKioL1gLekWgA9A7AAAjuDSmu5E710.png "title=" GIT branch management policy. PNG "alt=" Wkiol1glekwga9a7aaajudsmu5e710.png "/>

Bug Branch

git stash can put the current work site "storage", and so on after resuming work site, continue to work;

Git status can be used to view the current workspace after executing git stash should be clean

git stash list to see where the saved work site is.

There are two ways to recover: First, perform git stash apply recovery, and then execute git stash drop to delete stash content;

Second, do git stash pop, restore colleagues to the stash content also deleted.


Can be stash multiple times, restore the time, with Git stash list view, and then restore the stash, execute command git stash apply [email protected]{0}


Feature Branch

When new features are added

One, submit, merge, delete branch

Second, submit, cancel this new feature git branch-d name forcibly delete


Push Branch

Git push Origin Master

Git push Origin Dev


Label Management

Tag

git tag <name> can hit a new tag like git tag v1.0

View all tags with the git tag command

The default is to hit the most recent submission, if you have forgotten to tag, you can first use git log--pretty-oneline--abbrev-commit view the historical version, find the corresponding Commit-id number, execute the git tag tag Commit-id number .

git show <tahname> can see the details of the corresponding tag

git tag-a <tagname>-m "Information ..." to specify label information

git tag-s <tagname>-m "Information ..." can be signed with PGP tag


Push tags:git push Origin <tagname>

Push all non-push tags:git push Origin--tags

Delete local Tags:git tag-d <tagname>

Delete Remote tags:git push origin:refs/tags/<tagname>



Finish

This article from "Zero Egg" blog, declined reprint!

Git Learning (ii)

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.