Home > Back-end >  Git learning
Git learning

Time:09-16

# Git learning

Inus created the open-source Linux in 1991, since then, the Linux system development, has become the largest server system software,
Linus, although created Linux, Linux is growing by the enthusiastic volunteers in the world, so many people all around the world for Linux code, the Linux code is how to manage?
The fact is that in 2002 years ago, volunteers from all over the world send source code files through the diff to Linus, then by Linus himself through the manual way to merge the code!
You might think, why don't Linus put Linux code into the version control system? Wasn't there a CVS, SVN these free version control system? Because Linus firmly against the CVS and SVN, centralized version control system not only speed is slow, and must be connected to the Internet to use, there are some commercial version control system, although the CVS, SVN to use, but it was paid, and Linux open source spirit of
However, by 2002, Linux system has been developed for ten years, the code base of make it difficult to continue through the manual way management, Linus community brothers also expressed strong dissatisfaction on this way, and Linus chose BitKeeper a commercial version control system, the parent company for humanitarian spirit BitMover BitKeeper, authorized the Linux community free to use the version control system,
Good situation of stability and unity in 2005 was broken, the reason is that the Linux community people gathered, some unavoidable stained with the river's lake habit of liangshan, develop the Samba Andrew tried to crack BitKeeper agreement (and they were more than he do a), BitMover company found (monitoring work well done!) Nu, hence BitMover company, free access to reclaim the Linux community,
Linus can assure BitMover company an apology, after strict discipline, brothers, well, this is not possible, the reality is this:
Linus spent two weeks time for my own use C wrote a distributed version control system, it's a Git! Within a month, Linux system source code has been managed by Git! Cow is how to define? We can give it a try,
Git has quickly become one of the most popular distributed version control system, especially in 2008, making the website launched, it provide a Git for free open source project, many open source projects began to migrate to the lot, including jQuery, PHP, Ruby, etc.
History is such an accident, if not was threatening the Linux community BitMover company, may be we are not free now and super to use Git,

# # nouns explain

` HEAD ` HEAD is equivalent to a pointer, as he pointed to the version is the current display version, version can be understood as a wandering, can move back and forth between any version,

# # concept explanation

* the workspace

` workspace ` understandable for all files in the current folder, it is visible,

Modify ` ` workspace file and can add, delete, add after through ` git add ` command to add files to the ` ` registers

* the staging area

` ` registers I understood as a copy of work area and updated in real time, as long as ` workspace ` a file has changed, immediately modify the file status

Can pass ` git commit -m 'XXX' ` command will document submitted to ` current branch `

` ` staging area is a key ring, I think it is a part of the most bad understand, because it is not visible,

* the staging area to track changes

Git track management is to change, not file,

Definition of git revision: to modify the file to add and delete all call,

Git is how to track changes: for each modification, if not ` git add ` to ` ` registers will not join the ` commit ` in

* the current branch

` now I often use the concept of branch `, but also some fuzzy,

Understanding is a branch is now a production brigade,

First create a ` branch `

And then through a series of ` git add ` and ` git commit ` to complete ` current branch ` development tasks,

# # bug branch

Prospect feed: (

When there is a bug is in development, can create a bug branch ` ` branch to fix bugs - 001, but you're ` develop ` branches tasks haven't finished,

Also cannot submit, because you now development also need several days to complete, but the bug is more urgent, needs to be done immediately submitted,

At this point, just use the git ` git stash ` function, "storage" will be the development of the work site, such as continue to work, after returning to the scene after

Steps: (

* ` git stash ` to save the scene

* ` git status ` confirm the current branch is clean

* ` git checkout master ` if you are develop branch development, switch to the master branch to fix a bug

* ` git checkout - b bugs - 001 ` create bug branch and switch to the bug branch

*... . Repair of

* ` git add `, ` git commit - a `

* ` git merge master ` merged into master on

* ` git chekcout develop ` switch to develop work branch

* ` git stash pop ` restore job site, at the same time the stash content deleted

Can also be ` git stash appli ` field recovery then ` git stash drop ` delete stash content

* ` git stash list ` can query just save job site to which branch of the

# # command

* ` git diff ` + file

Where can view the current file has been modified

* ` git status `

View the current file status

* ` git add `

Add files to ` ` registers or add modify the file to ` ` registers

* ` git commit -m 'XXX' `

The ` ` registers all content submitted to the current branch

* ` git log `

Review existing in the log log a commit id ` b1a87 ` things like

* ` git reflog `

This is a view the commit command id, if not ` git log ` so long use this command to select which version you want to go,

* ` git reset - hard HEAD ^ `

Can be back to the current version of a version, if want to back up to a version is ` git reset - hard HEAD ^ ^ ` to back to up a ` git reset - hard HEAD ~ 3 ` so on

* ` git checkout - file `

Randomly changed ` a file to the workspace `, want to directly discarded ` workspace ` changes

* ` git reset the HEAD file `

Not only changed ` workspace ` a file, also ` commit to ` ` ` registers can use this command to return to is added to the ` workspace ` state, namely ` git add ` before

* ` git branch `

Check the branch

* ` git branch & lt; Name> `

Create a branch

* ` git checkout & lt; Name> `

Switch branch

* ` git checkout - b & lt; Name> `

Create + branch switch

* ` git merge & lt; Name> `

Merge a branch to the current branch

* ` git branch - d & lt; Name> `

Delete the branch

* ` git log - graph - pretty=oneline - abbrev - commit `

Can see branches merge figure




  • Related