Git Learning Summary

Source: Internet
Author: User
Tags git commands

1. Common git commands

Git init) Initializes a directory into the repository

Add File to Warehouse: ①git add + filename) Add file modifications to the stage (staging area) (can be added multiple times) ②gitcommit (submit to warehouse) Submit staging area content to the current branch

git status) to see if there are any modified and uncommitted in the current repository

git diff + filename) Displays the contents of the current file and the last modified content

git log) Displays the commit log from the most recent to the farthest (common git log--pretty=oneline) (Exit by Q)

Git reset--hard + version number) changes to a different version (head^ represents the previous version, head^^ represents the last version, head~100 represents up to 100 versions. Note: When selecting with version number, you can not write the full)

git reset HEAD + file) Staging area The changes back to the workspace

Cat + file name) View file contents

git reflog) record every command

git checkout--file Discard changes to the workspace, undo the changes (actually replacing the workspace version with the version in the repository)

Delete files from repository: ①git rm + file②git commit–m "description"

2. GitHub command

Git remote add origin [email protected]: User name/learngit Associate the current local warehouse with this remote warehouse

Git push-u origin master pushes all the contents of the local library to the remote library

git clone [email protected]: User name/gitskills clone a remote library to a local

Git push Origin branch name: pushes a branch to the remote repository

3. Git branch command

Git branch dev: Create Dev Branch

git checkout dev: switch to Dev Branch

Git checkout-b dev: represents creating and switching to the dev branch

Git branch: View Current Branch

git merge dev merges the content on the Dev branch onto the current branch

à (git merge--no-ff–m "merge with No--ff" dev) plus--no-ff parameters can be combined in normal mode, the merged branch has a history, can see that there has been a merger, and fast forward did not see the merger.

git branch-d dev: Remove Dev Branch

If two branches have been modified to prevent Git from merging automatically, you need to resolve the conflict first (resubmit the file again).

git log--graph: View Branch Merge diagram

Git stash hide the current workspace

git stash pop: Restore stash content and delete stash content

Summary: ①bug Branch--when fixing a bug, we will fix it by creating a new bug, then merge and finally delete it, and when the work is not finished, first put the work site git stash down, then fix the bug, fix it, then gitstashpop back to the job site.

② Develop a new feature (function), it is best to create a new branch.

If you want to discard a branch that has not been merged, you can forcibly delete it by using git branch–d name

4. Push Branches

? The Master branch is the main branch, so synchronize with the remote at all times;

? The Dev Branch is a development branch, and all members of the team need to work on it, so they need to be synchronized with the remote.

? Bug branches are only used to fix bugs locally, there is no need to push remote, unless the boss wants to see how many bugs you have fixed every week;

The feature branch is pushed to the remote, depending on whether you are working with your little partner on the above development.

Git Learning Summary

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.