git Concise tutorial

Source: Internet
Author: User
Tags diff github ssh key

Part I: Installation and configuration

1. Install git

Yum Install -y git

2. Initialize git

the test "  "[email protected]"

These two commands set up git accounts and mailboxes, respectively.

3. Associate a remote Git repository, where you'll do a demo with GitHub

(1). You first need to generate an SSH Key on your local machine

Ssh-keygen " [email protected] "

A successful build will generate a hidden directory in your home directory. SSH, which contains two files Id_rsa and id_rsa.pub.

Where Id_rsa is the private key, it is recommended not to divulge, id_rsa.pub is the public key,

[Email protected] ~]# CD ~/. SSH  VI id_rsa.pub
(2). Log in to your GitHub account and add all of the content in id_rsa.pub to the GitHub SSH key, such as:

Where the title can be filled out, key to write just generated

4. Clone the remote repository's code to a local

[[email protected] git]# git clone [email protected]:test/myfiles.gitinitialized empty git repositoryinch/root/git/myfiles/.git/remote:counting objects: -, Done. remote:compressing objects: -% (9/9), Done. Remote:total -(Delta0), reused -(Delta0), pack-reused0Unpacking objects: -% ( -/ -), Done.

Part II: Manipulating Files

1. Adding and modifying files

First add the file to the local disk, then add the file to Git's staging area and upload it to the remote repository GitHub, as follows:

VI"Add Readme file"[[email protected] git]# git push origin master 
Note: If a 403 error occurs with Git push, execute the following command first, then push (note that SSH is the way)
git remote set-url origin [email protected]:test/myfiles.git

Modify and add the same, directly edit the file after executing the above command.

2. deleting files

First delete the file locally, then delete the Git staging area file, and then commit the delete

RM rm Readme.txt [[email protected] git]# git push Origin Master

3. Undo Action

Here are two things:

(1). Modify the file, but do not commit git commit to staging area, can do the following actions to undo:

[[email protected] git]# git checkout--readme.txt  #注意,--no less, or switch to another branch

(2). If the file is modified and Git commit is committed to the GIT cache, you can execute git reset HEAD if you want to undo it, then git checkout--.

--Readme.txt

(3). View status

[[email protected] myfiles]# git status# on branch master# Changed and not updated:#    " git add <file>, ... . " To update what'll be committed) #   "git checkout--<file> " inch working directory) # #    modified   :"git add"  git commit-a")

The above results indicate that the Readme file has been modified, but it has not yet been submitted to the staging repository.

4. Version fallback

To fall back to a previous version if the file file was modified and the push was submitted to the remote repository

(1). Fallback to previous version

[[email protected] git]# git reset--hard head^  #回退到上面第二个版本用HEAD ^^ ..., 100th with head~

(2). Fallback to the version of the specified version number

[[email protected] git]# git reset--hard eab23e528f99cb53606554984ea1308005f8e35a   # EAB23E528F99CB53606554984EA1308005F8E35A is the version number, which can be preceded by several, such as eab23e528

(3). View Historical versions

If you want to see only simplified results, you can add--pretty-oneline parameters
[[email protected] git]# git log--pretty-oneline

5. View the differences between the current file and the file in the staging library

[[email protected] myfiles]# git diff HEAD--readme.txt
Diff--git A/readme.txt B/readme.txt
Index 6102AD0: 2C8B3B9 100644
---a/readme.txt
+ + B/readme.txt
@@-1 +1 @@
-it ' s my files ...
+it ' s My files

If the file is the same, there will be no echo.

Part III: Branch Management

Part IV: Label Management

Part V: Customizing git

git Concise tutorial

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.