Git tutorial Learning (iii)

Source: Internet
Author: User

7. Undo Changes

7.1. You can discard the workspace changes using git checkout for modifications that do not yet have git add

$ git checkout--readme.txt

Readme.txt If not git add, go back to the state in the master library (that is, the state of the last Git commit)

Readme.txt If you have git add and you have modified it, then go back to the state of git Add.

In general, it returns to the state of the most recent git commit or git Add.

7.2. You can use git reset HEAD file to undo changes that have not yet been git commit but git add

$ git reset HEAD readme.txtunstaged changes after reset:m       readme.txt

The action at this point is only for the git add file, which is different from the previous version (Git commit). This is equivalent to returning to the state before Git Add.

7.3. For changes that have been git commit, you can use git reset-hard head^ back to the previous version

8. deleting files

8.1. After deleting a file, to sync to the repository, use git rm

This command is similar to git add in that the workspace changes are put into the staging area (but one is an add operation, one is a delete operation)

' Test.txt '

8.2. Delete the file after deletion, to fallback the use of git checkout--test.txt

The function of Git checkout is to replace the workspace version with the version in the (master) version of the repository

$ git checkout--test.txt

9. Remote Storage

Not only does git provide the services of the Code warehouse locally, it can also provide a distributed code warehousing service. Host the code to a distributed code warehouse service provider GitHub. This allows you to rebuild existing code warehouses on GitHub on any machine. In addition, Because the free Code Warehouse service on GitHub is public code. So you can find a lot of other people's Code on the above clone to local.

The GitHub service requires you to register your account with GitHub and submit your local SSH hey to the GitHub to make pair of local repo and GitHub accounts

The steps are as follows:

1th step: Create ssh key$ ssh " [email protected] " The email address above will be the same as yours on GitHub. After completion in the. SSH directory can be found Id_rsa and id_rsa.pub two files, pub file is the public key, you can send someone to detect your private key (ID_RSA) encrypted content 2nd step: Login to GitHub, open "Account Settings", "SSH Keys" page: click 'add SSH key'and fill in the contents of Id_rsa.pub

10. Add a remote Library

10.1 Scenes

You build a git repository locally, you need to build the same git library on GitHub, and then sync the local content to the remote. This allows you to modify the library on any machine.

New Repo 2nd step: Enter repo name, click Create Repository 3rd Step: Run the following command in the local repo directory to associate the remote repo with the local $ git remote add origin [email protected]:m Ichaelliao/-u Origin master here the- u parameter is to associate the local master with the remote master

10.2 Push Master

After associating the local master with the remote origin, the local repository can be pushed to the far end by using the following command.

$ Git push Origin Master

11. Cloning from a remote library

11.1. Scene

There are already remote libraries and you need to clone the code from the remote library to local. The remote library here can be someone else's free library, or it can be your own

11.2. Pull

$ git clone [email protected]:michaelliao/gitskills.git

This command creates the Gitskills folder as the working directory under the current directory. So choose a folder before cloning.

Git tutorial Learning (iii)

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.