Git Learning Notes

Source: Internet
Author: User

This article has compiled a git tutorial with reference to Liaoche, compiled git learning notes, and used git commands for quick check: frequently used commands in color notation!

Git Learning notes
$ git config--global user.name "Your name" Configure user names for all warehouses in this machine
$ git config--global user.email "[Email protected]" Configure the email address of all warehouses in this machine
$ git init Initialize a Git repository
$ ls-ah View hidden directories, create a . Git folder after the warehouse is created (this is not a git command, just to view . git this hidden file)
$ git Add <file> Add files to a Git repository
$ git commit-m "Description text" Submit a file for the staging area to the repository
$ git status View Warehouse Status
$ git diff To view the differences between the workspace and the latest version of the repository
$ git diff <file> To view the differences between the specified file workspace and the repository
$ git log View each modified log, show commit ID, author, date, submit description text
$ git log--pretty=oneline View the log line mode, display the commit ID, submit the description text
$ git reset--hard head^ Fallback to previous version, can be used continuously.
$ git reset--hard <ID> Version fallback to the specified commit ID
$ git Reflog See the IDof each operation, such as commit Id,reset ID , etc...
$ git diff HEAD--<file> View the difference between the latest version of the specified file in the workspace and the repository
$ git checkout--<file>

Undo file <file> change in workspace, let <file> go back to the state of the last git commit or git add . Can be used for the work area to delete files by mistake. --very important, no--it becomes a "switch to another branch" command

$ git reset HEAD <file> Put file <file> withdraw staging area and return to workspace
$ git rm <file>

Delete the file files in the repository. The steps are:

1. rm <file> Delete file for workspace

2. Git rm <file> Delete file in Repository

3. Git commit-m "..." commit Delete

Delete the recovery step by mistake:

1. Git log--pretty=oneline view the pre-delete version number

2. Git reset--hard <ID> revert to pre-delete version

3. Git checkout--<file> recovery workspace Delete files by mistake

$ ssh-keygen-t rsa-c "[Email protected]" Create SSH Key
$ GIT push origin master Push the local master branch to the remote repository master Branch
$ git Remote add origin [email protected]:p Ath/repo-name.git Associate a remote Library
$ git clone [email protected]:chanliee/learngit.git Clone remote Repository to local, note to add SSH Key to GitHub
$ git Branch List all branches and monogram a * number in front of the current branch
$ git Branch <name> Create a branch
$ git checkout <name> Switch branches
$ git checkout-b <name> Create a branch, and then switch branches
$ git Merge <name>

Fast forward mode merges the specified branch <name> to the current branch, and discards the branch information after the branch is deleted.

If a conflict occurs, Git uses <<<<<<<,=======,>>>>>>> to mark the contents of different branches. You need to modify and then run git commit .

$ git merge--no-ff-m "Submission Instructions" <name> It is recommended to use Normal mode to merge branches, the merged history has branches, can see that there has been a merger, and Fast forward merge can not be seen to have been merged.
$ git branch-d <name> Delete Branch
$ git log--graph--pretty=oneline--abbrev-commit View the branch merge with the log with parameters
$ git log--graph Show the details of a branch merge
$ git stash The current work area "storage", and so on after the resumption of the site to continue to work
$ git Stash list View the list of staging area stash , showing the number of stash and where the branch
$ git stash apply [email protected]{0} Restore stash to workspace with label 0 , but stash content is not deleted
$ git stash drop [email protected]{0} Delete the stash labeled 0
$ git stash pop While recovering, the stash content was also deleted.
$ git branch-d <name> Forcibly delete a branch, if you want to discard a branch that has not been merged, you can use the command to forcibly delete
$ git remote viewing Remote Library information
$ git remote-v View Remote Library Details
$ GIT push origin <name> Push other branches
$ git checkout-b dev Origin/dev Create remote Origin 's dev branch locally to modify the remote dev Branch by modifying the way local Dev is pushed to the remote dev Branch
$ git push origin dev Push the local branch Dev to the remote Dev Branch, and if the push fails to indicate that the remote branch is newer than the local, you need to first use git pull to try to merge
$ git pull

If a conflict is committed, it needs to be committed after the code is merged, with git pull to grab the latest commit from Origin/dev .

Then, merge locally, resolve conflicts manually, commit commits , and push push

If git pull hints "No tracking Information", then the link relationship between the local branch and the remote branch is not created, using the following command:

$ git branch--set-upstream Dev origin/dev Specifies the link of the local dev branch to the remote origin/dev branch before pull can be linked
$ git tag <tag> Label the current ID
$ git tag <tag> <ID> Make a <tag> tag for a commit ID
$ git tag View tags in alphabetical order
$ git show <tag> View <tag> tag Information
$ git tag-a <tag>-M "description text" <ID> Create label with description, specify table signature with-A,-m specify descriptive text
$ git tag-d <tag> Remove Tags <tag>
$ GIT push origin <tag> Push a tag to a remote
$ GIT push origin--tags One-time push all not yet pushed to remote local label to remote
$ git push origin:refs/tags/<tag>

To delete a remote library label step:

1. $ git tag-d v0.99 Delete local tags
2. $ git push origin:refs/tags/v0.99 to remove remote library labels with push

Git Learning Notes

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.