Git, GitHub instructions (on)

Git, GitHub instructions (on)

First, prior knowledge:

1, GitHub is a git-based code hosting platform. Social programming can be achieved through Github.

2, Git: a distributed version control system . Git is no central server, no networking, everyone's computer is a complete repository. The user name and mailbox identification system as Git. Git system identification is displayed in the submission log.

$ git config --global user.name "your name"
$ git config --global user.email "[email protected]"

3, Git repository can track each text file modification and deletion of specific changes. Binary files , although the version control system can also be managed, but the version control system can not track file changes. Version control system can only binary files each modification to string together only know from pictures 1kb become 2KB , version control system also does not know binary file specific changes .

4, storage ( Repository ) Operation: Upload warehouse, warehouse detection

$ git remote add origin [email protected]:yourName/yourRepo.git

$ git clone username@host:/path/to/repository

5, warehouse (repository - a hidden directory '.git' ) and the relationship between the Git: local Git repository maintained by the three "tree" component. The first: the working directory that contains the actual file; second: the staging area (stage or index) , it is like a buffer area that temporarily stores the user changes; third: the HEAD last time, point the user submits in this branch pointer results. HEAD has in each branch. After branches merge, the user can, by working on a branch of the branch HEAD. The master merge just pointing to the content currently using branch HEAD pointer.

6, the workspace + repository (repository .git) {staging area (index or stage) + HEAD (directed to the user the results of the last commit pointer in the branch) + master}

7, SSH protocol is a network for Internet host between visits and information exchange . Host Key as the basic key mechanism. SSH protocol requires that each host using the SSH protocol must have at least one of its own host key pair , serving side by client side host key after certification, in order to allow its connection request.

8, branches: on the branch, the file every time changes are committed. Git branch regarded the different file versions strung together a timeline, this timeline is a branch.

9, the working tree: Content in .git directory called "working tree attached to the warehouse." Edit the file operations such as work carried out in the tree, then recorded the warehouse, order management file history snapshots .

Four states 10, a file in the working directory: untracked, unmodified, modified, staged . Warehouse contains at each time point file snapshot .

 

Two, Git operation command:

1, git init: to become git directory can manage the warehouse. Initialized empty Git repository in d: /www/testgit/.git/

2, git add: add files to the staging area

3, git commit -m: the submission of documents to the repository. git commit time to submit input information by calling vim editor to be written information, use the command vim editor of the operation.

  Commit message format: first line: a line of text submitted content DESCRIPTION; Second row: the empty row; after the third line: Causes and detailed description changes

  git commit --amend: Modify submit information

  git rebase -i HEAD-2: compression history. Two recent history of the selected current branch HEAD included (recently submitted), including as an object, open the editor, the editor contents Pick >> Fixup .

4, git status: check the status of the warehouse to view the documents submitted to the queue if there are uncommitted files, trace files are changed

5, git diff: see the difference working tree and staging areas; git diff HEAD and working tree to view the latest submitted difference

6, git log: View commit log , display furthest from the most recent commit log to

$ git log 

$ git log –pretty=oneline

7, git reset --hard HEAD ^: the current version to fall back to the previous version; ^ hard HEAD: The previous version, hard HEAD ^^: a version on, hard HEAD ~ 100: the first 100 version

8, git reflog: view the current warehouse operation log, including: commit, reset, checkout, merge and other log operations

9, git reset the hash value --hard a point in time: According to the hash value of the target point in time, place the file in the specified version.

10, git Branch feature-A: create feature-A branch

. 11, Git Checkout  feature-A: Switch to feature-A branch

12 is, Git Checkout  -b feature-A: and switch to create a feature-A branch

 

Three, Git version management system " branch " concept

Branch Basics:

Branch: Branch is used to feature development insulated come. When the user creates a warehouse, Master is the "default" branch. Users can develop on other branches, reviewed, after the completion of their merger to the main branch.

Co-cultivation branch

Branch operation:

1, create a branch, and -b parameter indicates the handover branch, corresponding to execute: Git Branch feature_x + Git Checkout feature_x two instructions, direct switching without increasing the -b parameter existing branch.

$ git checkout -b feature_x

2, see the branch, with an asterisk for the current branch

$ git branch

3, the combined branch modifications will occur in the branches feature_v merge into the main branch in master. When combined just master pointer to feature_v.

$ Git go feature_v

4, delete branch

$ git branch -d feature_v

Branch Management Strategy:

1, "Fast forward" mode ( "fast forward mode"): directly to the master point feature_v is currently committed , so the merger is very fast. In this mode, delete the branch, the branch will lose information.

2, parameter -no-ff to disable "Fast forward" mode, delete the branch, the branch information is also deleted.

3, git merge --no-ff feature-C, integrated feature-C branch of the branch master.

Branch conflict:

1, branch conflict situations: in the different branches have to modify the same file and will commit the changes .

2, modify the file to open branch conflict occurs between the content <<<<<<< HEAD ======= >>>>>>> that they can not merge correctly conflict section.

3, prior to the merger difference can be changed by the preview command:

git diff <source_branch> <target_branch>

stash features:

0, the current command git stash of hidden work such as the restoration site continue to work after

1, the command git stash list: view a list of all files that are hidden

2, the command git stash apply: recover hidden files, but does not remove content

3, command git stash drop: Delete Files

4, the command git stash pop: while restoring files also delete files

 

Fourth, the remote repository (the default name is the origin):

1, between Github repository and local Git repository through SSH visits and exchange of information. We need to create a local SSH key. "[email protected]" is a mailbox user registration GitHub binding.

ssh-keygen  -t rsa –C “[email protected]

 Note: After the completion of more instructions executed, ~/the generated .sshfolder. Folder has id_rsa and id_rsa.pub these two files. id_rsa is the private key , id_rsa.pub is the public key . Add id_rsa.pub public key to Account Settings (account configuration) GitHub settings in the left select SSH Keys, Add SSH Key.

2, GitHub repository and create a local Git repository synchronization. GitHub repository as a backup local Git repository, but also so that others on the local Git repository to collaborate by executing the command of the GitHub repository implementation.

2.1, the following command contents of the local Git repository pushed to GitHub repository, the command git Remote -v : View details of the remote repository

$ git remote add origin https://github.com/minboyin/testgit.git

2.2, for the latest remote repository branch

$ git pull  origin feature-A

Note: If you are a new warehouse (repositories), then the pull of code when appears: fatal: Could not find remote ref master translation is: Fatal: Can not find the remote reference master , is negligible , direct submission you can.

2.3, Git repository specified local branch pushed GitHub, -u parameters : the origin of the master repository for the current branch arranged upstream branch local repository (upstream), usually selected master branch! Local branch warehouse current branch can obtain content directly from the master origin warehouse, eliminating the trouble of adding parameters.

$ git push -u origin master

2.4, the remote repository (in warehouse GitHub) cloned into local, establishment of a consistent local repository. The default implementation of the completion of the master branch.

$ git clone https://github.com/minboyin/testgit.git

 2.5, copy a remote repository branch (origin warehouse) to a local, establish a consistent local branch. Behind -b parameter is the name of the local branch

$ git checkout -b feature-A origin/feature-A

3, remote collaborative work modes:

1, first of all, may attempt to use git push origin branch-name push the present user to modify the partition.

2, if the push fails, because the remote branch earlier than your local update, you need to use git pull attempt to merge. pull git - rebase Origin Master .

  2.1, --rebase : Cancel the local library just commit, and send them to the repository after the update.

  2.2, git pull git FETCH + = Merge git : git FETCH is to pull the latest content remote host local, git pull incorporated directly pull down the latest content sucked the remote host.

3, if the merger there is a conflict , we need to view and resolve conflicts , and submitted locally. Then git push origin branch-name modifying the user pushes this partition.

 

 

 

Guess you like

Origin www.cnblogs.com/yinminbo/p/11797730.html