GitHub Self-study documentation I hope to give beginners some help.

Source: Internet
Author: User
Tags diff

One, the installation of git

installation under Windows:https://git-for-windows.github.io download from here completely brain-free installation.

When the installation is complete, find Git Bash in the Start menu to indicate that the installation was successful.

Then, at the command line, enter:

$ git config--global user.name "Your name"

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

Two

1. Create a version library

The first step is to open gitand switch to the folder where you want to create the repository.

For example:

$ mkdir Learngit

$ CD Learngit

$ pwd

/users

The PWD command is used to display the current directory. On my Mac, this warehouse is located in/users.

PS: Using Windows systems, in order to avoid encountering a variety of inexplicable problems, make sure that the directory name (including the parent directory) does not contain Chinese.

The second step is to use the GIT init command to turn this directory into a repository that git can manage ( the initialization of Git)

2. Add files to Repository

Under the Learngite folder , create a file named Readme.txt. feel free to add content inside the document.

Never edit any text file using Windows-brought notepad

The first step is to use the command git add to tell git to add the file to the repository

$ git Add readme.txt

Execute the above command without any display, that's right, the Unix philosophy is "No news is good news", stating add success.

In the second step, use the command git commit to tell git to commit the file to the repository:

$ git commit -M "wrote a Readme file"

[Master (root-commit) Cb926e7] wrote a readme file

1 file changed, 2 insertions (+)

Create Mode 100644 readme.txt

Git commit command,-m after the input is the description of the submission, preferably meaningful, easy to modify later.

Three-version control

1. Run the git status command to view the status of the current file:

$ git status

# on Branch Master

# changes not staged for commit:

# (use "git add <file> ..." To update what would be committed)

# (use "Git checkout-<file> ..." to discard changes in working directory)

#

# Modified:readme.txt

#

No changes added to commit (use "git add" and/or "git commit-a")

The git status command allows us to keep abreast of the current state of the repository, which tells us that Readme.txt has been modified, but not yet ready to commit the changes.

2. Use Git diff to view the file changes, if there are changes can be submitted with git add , and then git commit-m ' modify prompt ', to update the version.

Four-version backtracking

1 use git log to view git logs.

The git log command displays the commit log from the most recent to the farthest

The git log--pretty=oneline command is used to view the git version number (commit ID) in hexadecimal notation

2. With the git reset--hard head^ command back to the previous version, head~10 back to the previous version.

$ git reset --hard head^

. Git reset--hard commit ID, which indicates backtracking to the specified version

PS: Understanding of working area and staging area

When you add a file to a git repository, it is executed in two steps:

The first step is to use git add to add the file, in fact, the file is modified to add to the staging area;

The second step is to commit the change with git commit, which in effect commits all of the staging area content to the current branch.

git diff HEAD-The Readme.txt command indicates the difference between viewing the version of the workspace and the latest version of the repository.

Git is tracked and modified, and if you do not add to staging area, it will not be added to the commit.

Command git checkout--readme.txt means to undo all changes to the Readme.txt file in the workspace, here are two things:

One is that Readme.txt has not been put into the staging area since the modification, and now, the undo changes back to the same state as the repository;

One is that the Readme.txt has been added to the staging area and modified, and now the undo changes go back to the state that was added to the staging area.

All in all, let this file go back to the state of the last git commit or git Add.

2 The second case to add the modified file has been added to staging area, the first step is to use git reset HEAD file (file name) to undo the staging, and then use git checkout-file (file name) to cancel the modification.

3 RM file (file name) deletes a file.

(1) If you decide to delete using the delete command git rm file (filename) to completely delete the file, then need git commit-m ' deleted a xxx file '.

(2) If you delete the error, use git checkout-file (filename)

V. Remote Library creation

To associate a remote library, use the command git remote add origin [email protected]:p ath/repo-name.git;

Once associated, use the command Git push-u Origin master to push all the contents of the master branch for the first time;

Thereafter, after each local commit, whenever necessary, you can use the command GIT push Origin master to push the latest changes;

To clone a warehouse, you must first know the address of the warehouse and then use the GIT clone address command to clone

See which remote repositories are currently configured, and you can use the Git remote-v command

VI Create a branch

View branches: Git branch

Create a branch: Git branch <name>

Switch branches: git checkout <name>

Create + switch branches: git checkout-b <name>

Merge a branch to the current branch: git merge <name>

Delete branch: Git branch-d <name>

When git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.

You can see the branch merge diagram with the git log--graph command.

To switch the location of the remote library: Git remote Set-url origin https://github.com/hollychengjianhua/learngit.git

GitHub Self-study documentation I hope to give beginners some help.

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.