GitHub Detailed Tutorials

Source: Internet
Author: User

Tutorial Source: http://www.cnblogs.com/God-/p/5556531.html

In the 1.4~1.5 section of the tutorial, the commands are interspersed with other code, which is handy for later viewing. The rest of the original tutorial has been described in very clear detail.

1.4 Start working with Git

1.4.1 Create some files below, they will be put into version control

CD ~ # Switch to Home

mkdir ~/repo01 #Create a directory

CD repo01 #Switch into it

mkdir datafiles #Create A new directory

Touch test01 #Create a few files

Touch test02

Touch test03

ls > test01 #Put a little text into the first file

1.4.2 Creating warehouses, adding files, and committing changes

Each git repository is placed under the. git folder. This directory contains all the history of the repository, and the. git/config file contains the local configuration of the warehouse.

The following will create a git repository, add files to the index in the warehouse, and commit the changes.

Git init #Initialize the local Git repository

git Add. #Add All (Files and directories) to the Git repository

Git commit-m "Initial commit" #Make a commit of your file to the local repository

git log # Show the log file

1.4.3 diff command and commit change

With the git diff command, the user can view the changes. By changing the contents of a file, see what the Gitdiff command outputs, and then commit this change to the repository

echo "A change" > test01 #Make Some changes to the file

echo "And this are another change" > test02

Git diff #Check the changes via the diff command

Git commit-a-M "These is new changes" #Commit the changes,-a'll commit changes for modified files, but would not Add automatically new files

1.4.4 Status, Diff, and Commit Log

Below you will be shown the current status of the warehouse and the history of past submissions.

echo "A new change" > test01 #Make Some changes in the file

echo "And this are another new change" > test02

Git status #See the current status of your repository (which files is changed/new/deleted)

git diff #Show The differences between the uncommitted files and the last commit in the current branch

git Add. && git commit-m "Changes in the Commmit messages" #Add the changes to the index and commit

git log #Show The commits in the branch

GITK--all #This starts a nice graphical view of the changes

1.4.5 Correcting submitted information-git amend

With the git Amend command, we can modify the last submitted information. There is an error in the commit message above, and this error is modified below.

git commit--amend-m "more changes-now correct"

1.4.6 Deleting files

If you delete a file under version control, use git Add. This file is not deleted in the index. You need to do this through the git commit command with the-a option and the-a git add command.

Touch Nonsense.txt #Create A file and put it under version control

git Add. && git commit-m "a new file has been created"

RM nonsense.txt #Remove The file

git Add. && git commit-m "a new file has been created" #Try standard-of-the-committing- Not work

Git commit-a-M "File Nonsense.txt is now removed" #Now commit with THE-A flag

Git add-a. git commit-m "File nonsense.txt is now removed" #Alternatively you could add deleted files to the staging Index via

1.5 Remote Storage (remote repositories)1.5.1 to set up a remote git repository

We will create a remote git repository. This repository can be stored locally or on a network.

The remote Git repository and the standard Git repository have the following differences: A standard git repository includes source code and historical information records. We can modify the code directly on this basis, because it already contains a working copy. However, the remote repository does not include a working copy and includes only historical information. You can use the –bare option to create a warehouse like this.

For convenience, the warehouse in the example is created on the local file system

CD ~/repo01 #switch to the first repository

git clone--bare. .. /remote-repository.git

LS ~/remote-repository.git #Check The content, it's identical to the. git directory in repo01

1.5.2 Push changes to other warehouses

Make some changes, and then push these changes from your first warehouse to a remote repository

CD ~/repo01

echo "Hello, hello." Turn Your radio on "> test01

echo "Bye, Bye. Turn Your Radio Off "> test02

Git commit-a-M "Some changes"

git push: /remote-repository.git

1.5.3 Adding a remote repository

In addition to accessing the Git repository through a full URL, you can add a short name to the repository via the GIT remote add command. When you clone a Repository, Origin represents the original repository that was cloned. Even if we start from scratch, this name also exists.

Git remote add Origin: /remote-repository.git #Add. /remote-repository.git with the name origin

echo "I added a remote repo" > test02 #Again some changes

Git commit-a-M "This was a test for the new remote origin" #commit

Git push origin #if you does not label a repository it would push to Origin

1.5.4 display of existing remote repositories

View the remote repository that already exists by using the following command

Git remote # Show the existing defined remote repositories

1.5.5 Clone Warehouse

Create a new warehouse under the new directory with the following command

CD ~ #Switch to Home

mkdir repo02 #Make New Directory

CD ~/repo02 #Switch to new directory

git clone. . /remote-repository.git #clone

1.5.6 Fetch (pull) Change

By pulling, you can get the latest changes from other warehouses. In the second warehouse, make some changes, and then push the changes to the repository at the far end. Then pull these changes in the first warehouse

CD ~ #Switch to Home

CD ~/repo02 #Switch to second directory

echo "A change" > test01 #Make changes

Git commit-a-M "A change" #commit

Git push origin #push changes to remote Repository, origin was automatically maintained as we cloned from T His repository

CD ~/repo01

Git pull. . /remote-repository.git/#Switch to the first repository and pulled in thechanges

Less test01 #Check the changes

1.5.7 revert changes

If you create a file that you do not want to commit in your working copy, you can discard it.

Touch test04

echo "This was Trash" > test04 # Create A new file with content

Git clean-n # Make a dry-run to see what would happen,-N is the same as--dry-run

Git clean-f # now delete

You can extract the old version of the code by submitting the ID. git log command to view the commit ID

cd ~/repo01 # Switch to Home

git log

git checkout Commit_name # Copy One of the older commits and checkout the older revision via translator NOTE: Checkout plus commit I D is to copy the commit content to index and the working copy

If you haven't added the changes to the index yet, you can also restore all the changes directly

echo ' nonsense change ' > test01 #Some nonsense change

git checkout test01 #just checkout the old version, translator Note: If there is no commit ID number after checkout, copy the data from index to the working copy And does not involve changes in the commit part

Cat test01 #Check The result

Echo ' Another nonsense change ' > test01 #Another nonsense change

git add test01 #We Add the file to the staging index

git reset head test01 #Restore the file in the staging index, the translator notes: Copy the test01 file of the commit that the head refers to in index

git check test01 #Get the old version from the staging index, translator Note: Copy the index test01 to the working copy, the translator notes, the above two commands can be merged into Git Checko UT HEAD test01

git revert commit_name #也可以通过revert命令进行还原操作, revert a commit

Even if you delete a file that has not been added to the index and submitted, you can also restore the file

RM test01 #Delete a file

git check test01 #Revert the deletion

If you have added a file to the index, but not committed. You can remove this file from the index by using the git resetfile command

Touch incorrect. txt//Create a file

git Add. Accidently add it to the index

git reset incorrect. txt //Remove it from the index

RM incorrect. txt //Delete the file

If you deleted the folder and have not submitted it, you can recover the folder by following the command. Translator Note: Even if it has been submitted, it can be restored

git checkout HEAD--Your_dir_to_restore

Translator NOTE: Checkout and reset the meanings of these two commands are different and can be read in this article http://marklodato.github.com/visual-git-guide/index-en.html

1.5.8 Mark

Git can use any version of the history to mark it. This can be easily found in subsequent releases. In general, it is used to mark the version of a release. All tags can be listed by using the git tag command to create a tag and revert to a tag with the following command

git tag version1.6-m ' version 1.6 '

git checkout <tag_name>

That ' s all~~~~

GitHub Detailed Tutorials

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.