Git basic operations and git basic operations

Source: Internet
Author: User

Git basic operations and git basic operations
Git simple tutorial

This tutorial only includes basic git operations.

1. Create a repository

Create a folder using mkdir

Pwd displays the current directory

Git init: Code the current directory to a git-managed Repository

2. Add the file to the version Library

Add the file to the directory or its subdirectory created in step 1. perform the following steps:

1 git add readme.txt

Add a file to a repository

2 git commit-m "wrote a readme file"

-M is followed by the description of this submission.

3. view the status

Git statue

Master the warehouse status, including whether the Warehouse is modified

Git diff

Compare the changes made in the previous version to view the changes.

4. Version rollback

Git log

Display git file submission records

Git log -- pretty = oneline

Simplified display of version changes

Git reset -- hard HEAD

Roll back to the previous version

In git, HEAD indicates the current version, HEAD ^ indicates the previous version, and HEAD ^ indicates the previous version ~ 100 indicates that the version is up to 100

Git reset -- hard version

Roll back to the specified version (only the first few digits are required for the version number)

Git reflog

Record each modification record and the ID of the corresponding version. After obtaining the ID, you can return it from the old version to the new version.

5. Work zone and temporary storage Zone

The add command adds the file to the temporary storage area. commit submits the content of the temporary storage area to the current branch.

Git submits changes to the temporary storage area rather than the workspace. The modified file is submitted to the temporary storage area through the add command, and then the commit command can be used to complete version management.

6. Cancel Modification

1. When you change the workspace content but want to discard the workspace modification, run the following command:

Git checkout -- filename

2. You not only modified the workspace content, but also submitted it to the temporary storage partition. When you want to discard the modification, run the following command:

Git reset HEAD filename

7. delete an object

1. delete a workspace File

Rm filename

2. delete files from the version Library

Git rm filename

After deletion, run the git commit-m "description" command again to completely delete it.

3. Delete the workspace by mistake and restore from the Repository:

Git checkout -- filename

8. Add a remote database

Associate a remote database with the following command:

Git remote add origin git @ server-name: oath/repo-name.git

After Association, submit the command for the first time:

Git push-u origin master

For subsequent submission of the same database, run the following command:

Git push origin master

9. Clone from remote database

Use the Https protocol to clone the remote database (slow speed) and run the following command:

Git clone https

10. Branch Management

-Create a branch dev

Git branch dev

Switch to branch dev

Git checkout dev

Create and switch to the current Branch

Git checkout-B dev

View Current Branch

Git branch

The current branch will be marked *

Submit current Branch

Git add current_branch_file

Git commit-m current_branch_file

Switch to main branch

Git checkout master

Merge the dev branch into the master branch git merge dev

By default, quick foward is used for git merge. You can use the-no-ff parameter to disable Fast foward:

Git merge -- no-ff-m "merge demo" dev

Delete dev Branch

Git branch-d dev

Related Article

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: [email protected] 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.