It's time for the system to understand Git version control

Source: Internet
Author: User
Tags log log git client using git git clone git commands

git client installs Git

git client Installation

Today, with GitHub, git commands, to understand how to implement open source code base and version control

GitHub is a hosted platform for Open source and proprietary software projects, because it only supports git as a unique version library format for hosting
So we need to download a git client software to execute a variety of instructions

git download Address: https://git-scm.com/

After downloading, configure the PATH environment variable, E:\develop\git\Git\bin (my native is under E disk)

Enter the git command in the Doc Command Line window, if the following information appears, indicating that the installation was successful.

C:\users\67334>git
usage:git [--version] [--help] [-c <path>] [-C Name=value]
           [--exec-path[=< PATH>] [--html-path] [--man-path] [--info-path]
           [P |--paginate |--no-pager] [--no-replace-objects] [--bare]< C4/>[--GIT-DIR=<PATH>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args These are

are common Git commands used in various situations:

Click the right mouse button and the menu bar will appear git GUI and git Bash
Gui:graphical user Interface (Users graphical interface)
Bash: Is the command line tool under Windows

Version Storage warehouse:

Public:
    -GitHub 
    -code cloud
builds itself:
    
git Life

Make
Next i use git command, step by step implementation GitHub release project, version control function

1, first on the computer to create an empty folder, I for this empty folder named demo, and then enter the folder
First executed at Git terminal, git init instruction, will be generated in the Demo folder. Git folder

2, in the Demo folder to create a a.txt file, and then through Git status View, the directive function is
Lists modified (green ID), newly created (red ID), temporary but uncommitted files (white ID)

3, then add a file via Git (git add, add all) to the new a.txt file we just created

4, then through git commit-m "Memo information", submit this content

The above 4 steps of Operation effect screenshot as follows:

5. We use the instructions above to add a b.txt file to the Demo folder and then view our action records through git log, and then we can query the log log of our add a.txt and B.txt, and then pass git Reset--hard b96f962d0f835e3114b6f51bf7c9bfe6125626e3, go back to our operations node, at this time I fall back to the first time to add a file node, The demo folder has only one a.txt file, the following is a screenshot of the effect of the Git end

6, at this point to view git log results found that there is only one operation record, that is, we added the a.txt of the record, we did the second step of the operation. That is, when we add the b.txt file node, how do we fall back to the last node?
We can use Git reflog

7, now the demo folder in the 2 file contents
The a.txt text reads as follows:

Initializing content

The b.txt text reads as follows:

This is B text content

We continue to add the following record information for B.txt

We temporarily add a record for B

At this moment the B.txt document reads as follows:

This is the B text,
we're adding a record for B.

The above meaning is to update the contents of the B.txt file, add the action record
If we use the development scenario, we are in demand 1, however, due to the work needs, demand 1 need to put aside, we need to do demand 2, demand 1 code needs to be cut off, and so we finish the demand 2, We continue to need to get 1 of our previous code, we can take advantage of the git stash command, the following is the meaning of the command

Git stash             stores all modified content in the current workspace to "somewhere", restores the workspace to the current version of the unmodified state
                git stash list        view all records stored in "Somewhere"
                git stash Clear     empty "Somewhere"
                git stash pops       to get the first record back to the workspace from "somewhere" (possibly conflicting)
                git stash apply     number, assign the specified number record from "Somewhere" Get back to the workspace (there may be a conflict) 
                git stash drop      number, delete the specified number of records

This time there will be conflict, we need to resolve the conflict, you can
8. We can view all the branches of our project through Git branch, by default there is only one master branch, we can create a new branch through Git branch dev (Dev is our branch name), name is dev Development Branch, then through Git checkout Dev switches to our new Dev branch, we can also create and switch branches by git checkout-b branch name

9, we switch to the Dev branch, through the touch file name to create a file, and then add, commit, meaning that the dev branch to make some changes, and save in the Dev branch, and then in the cut back to the master branch, we have to do is the dev on the updated content, Also make the same modifications on master, we can merge the updates on dev with the git merge branch name to master
Delete Branch also using git branch-d branch name

10, the use of GitHub to create projects, the following instructions will appear, need to create a build project in Git terminal input,
To add a new remote repository, you can specify a simple name for future reference and run Git remote add [shortname] [url]:
Through git remote add Origin https://github.com/iyongfei/test.git

11, next we through Git clone https://github.com/iyongfei/test.git to clone download our GitHub project, we pull by default is the Master branch (the default branch can be in GitHub set other branches)
Then git add, based on the previous git instructions. and git commit-m "Memo info",
Note that since project development is all collaborative development, we need GIT pull Origin branch before submitting the code, pull the corresponding branch code, and then if there is a conflict resolution, then in GIT push origin the branch name

PS: I screenshot below when submitting code, in order to simplify operations, no git pull

12. We can also add new branches to the GitHub project, we create branches through GIT branch branch, switch branches through git checkout branch, (or create and switch branches through git checkout-b branch), and then add, submit ( I'm not adding any information here), and finally git push Origin dev to add a new branch to the GitHub project

13, we can also pull the contents of other branches to this branch, such as I add content on master, and then I went to the dev branch to pull the code on master, and then submitted to the corresponding GitHub branch dev (i still do not add additional content)

14. How conflicts arise. How we resolve conflicts.
When you pull the Dev code, colleagues also pull the Dev code, colleagues before I submit the code, and then I also locally modified the code, if the same file, there will be conflict, pull the dev code will fail again, and the submission failed

Solution one: First in their own local dev, through git stash temporary changes, and then git pull branch code, and then git stash pop merge generation, resolve the conflict (delete the code we do not need), and then in the submit code

<<<<<<< Updated upstream
aa for each
BB extra minute
=======
aac
BBD
>>> >>>> stashed changes

Workaround two: Do not use git stash, using compare contrast software, will have conflicting files, cut out, and then pull the Dev branch code, the GitHub dev branch of the latest code, sync down, and then in their own cut out of the Code section, to compare, Update your own code to the synchronized code, and then submit it to the GitHub corresponding branch

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.