Git basic commands

Source: Internet
Author: User

1. Configure user information in git.

Enter the following command settings in the command line. You only need to set the settings once.

Git config -- global user. Name "Joey joejoe"

Git config-global user. Email "joey@joejoe.com"

 

2. initialize the project

The following operations are performed in the main directory of the project. The project files can be extracted from the tar.gz and ZIP files or created by yourself.

CD myproject/

Run the initialization command

Gitinit

Add all files in the current directory to git

Gitadd.

Submit update

Git commit

This will prompt you to write the submitted information, which is used to describe the content just submitted for future query. The initial commit can be written here.

Save and exit.

 

3. General Workflow

Generally, follow these steps:

A. Write or update the program in the project.

B. Check the changed files.

Git status

C. Check the actually changed files.

Git diff

D. Add the files or directories or other new files seen in B to the GIT repository.

Git add file1 newfile2newfolder3

E. Confirm submission,

Git commit

F enter the submission information. If the change is abandoned, exit the editor.

 

4. view the project status

View the current work

Git log

View the last three submissions

Git log-N3

Complete viewing

Git log -- stat -- Summary

 

5. View changes

View submitted updates

Git diff

View the ID of the change, for example

Git log-pretty = oneline

Bytes ---------------------------------------------------------------------------------------------------------------

6c93a1960072710c6677682a7816ba9e48b7528f removepersist. clearscriptcache ()

C6e7f6e685edbb414c676df259aab989b617b018 makegit ignore logs directory.

8fefbce334d30466e3bb8f24d11202a8f51_1c initialcommit.

Bytes ---------------------------------------------------------------------------------------------------------------

The first 40 letters of each line are the updated idnumber. These numbers will also appear when git commit is executed. The difference between the two changes is that you need to use it. For example, when judging the differences between update point 1 and update Point 2:

Git diff 8fef .. c6e7

It can be seen that 40 letters do not need to be entered in all, but only the first few digits can mark an update point.

To view the last update point, you can use:

Git diff head ^ .. head

 

6. Fix errors

The changes have not been submitted and you do not want them. In this case, you can discard these changes:

Git reset -- hard

You can also perform such operations on a single file, but the commands are a bit different:

Git checkout myfile.txt

In the previous submission, I forgot to add some files. You can easily correct them:

Git reset-soft head ^

Git add forget.txt test.txt

Then submit.

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.