Simple use of Git

Source: Internet
Author: User
1. Git repository Initialization
  • This repository stores the files backed up by git for our project.

  • Right-click the project directory and choose git bash.

  • Command:git init

2. Configure user information:
  • It is to set who the current user is. After each backup, the information of the backup user is stored.

  • Command:

    • Configuration Username:git config --global user.name "wanglong"

    • Configuration Email:git config --global user.email "[email protected]"

3. Store the code in the. Git Repository:
  • 1. Put the code in the GIT staging area:

    • git add ./01.txt: Place the specified file in the temporary storage area.

    • git add ./: Put all modified files in the temporary storage area.

  • 2. Store the file at the warehouse entry to the version Library:

    • Git commit-M "file description".

  • 3. All modified files can be put into the version library at one time + command:Git commit -- all-M "some instructions"

4. view the current status
  • You can check whether the current code has been put into the warehouse:

  • Command:git status.

5. Ignore files in git
  • . Gitignore: Set the ignored files and directories in this file.

  • Ignored files are not submitted to the warehouse.

  • Statement:

    • /..dea: The. DEA file is ignored.

    • /js: All files in the JS directory are ignored.

    • /js/*.js: All files suffixed with. js under the JS directory are ignored.

6. View logs
  • git log: View historical submitted logs

  • git log --oneline: You can view the logs of the simplified version.

7. Roll Back to the specified version
  • git reset --hard Head~0: Indicates to roll back to the status of the last code submission (may be 0, 1, 2 ...).

  • Git reset -- hard [version number]: Accurately rolls back to a submitted status.

  • git reflog: You can see the record of each version switch: You can see all submitted version numbers.

8. Branch
  • MASTER: Default master Branch

  • git branch dev: Create a branch. The content of the branch is the same as that of the original branch.

  • git chechout dev: Switch Branch

  • git branch: View the current branches

  • git merge dev: Merge Branch

    • Merge the current branch with the specified branch.

  • git branch -d dev: Delete Branch

  • When there is a conflict in the merge (manual merge is required), delete unnecessary components and resubmit the modified Code.

Submit code to GitHub
  • Git push address (the content of the current branch will be uploaded to the remote master Branch) Master

Obtain data from GitHub warehouse
  • git pull https://github.com/nameWangLong/test01.git master+ Before downloading, You need to initialize a repositories.

  • Git clone [address]: A New file is created to obtain the file in the remote warehouse. Multiple operations will overwrite the file.

Upload code using SSH:
  • Public Key and Private Key

  • Command for generating public and private keys:Ssh-keygen-t rsa-c "email"

  • Add the generated public key or private key to SSH in GitHub Project Settings

  • git push [email protected]:nameWangLong/test01.git master

Push and pull operation sequence:
  • Pull first resolves conflicts and then pushes them to the server.

Push and pull for simplified operations
  • First, define a Remote Variable pointing to the address:git remote add origin [email protected]:nameWangLong/test01.git master

  • Then add the-u parameter to the push type.git push origin -u master

  • After uploading and downloading, you only need to entergit push git pull 

 

 

 

Simple use of Git

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: 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.