Git basic usage

Source: Internet
Author: User
Tags tagname using git

Git

git initialization git initadd a document to git add <filename>, add all the files using git Add.submit a document added or modified git commit-m "message"view state git statusSee what's Changed git diff filenameView history git logsversion fallback: Git Reset-hard head^, where head^ represents a fallback to the previous version, head^^ back to the previous version, back to the last 100 versions using head~100Keep a record of every command git reflogback to the specified version of Git Reset-hard 39321 (commit ID)Git can only be submitted if the file is modified and if it is added to staging area using the Add command, even if there is no add, it cannot be submitted.undo a modified file git checkout-filenamewhen the modified file has an error and has been added to staging area, you can use the command git reset HEAD filename to undo the modified file from staging area and back to the workspace

Scenario 1: When you mess up the contents of a file in your workspace and want to discard the workspace changes directly, use the command git checkout -- file .

Scenario 2: When you not only changed the contents of a file in the workspace, but also added to the staging area, want to discard the changes, two steps, the first step with the command git reset HEAD file , back to Scene 1, the second step by scene 1 operation.

Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, refer to the version fallback section, but only if it is not pushed to the remote library.

Delete a file git rm filename and then submit it

After you delete a file from your local repository, you can use git checkout--filename to recover the file

Commit a local git to a remote github

First generate a local public key and secret key, use the command ssh-keygen-t rsa-c "[email protected]", and then set the Sshkey in GitHub, add the public key to GitHub

Using git remote add origin [email protected]:michaelliao/learngit.git

Then use Git push-u origin master to push local content to the remote library

Create a branch and switch to the branch git checkout-b branch name

View current branch using GIT branch

Toggle Branch git Checkout branch name

Merge branch git Merge branch name

Remove branch git branch-d branch name

GIT encourages the use of branching:

To view branches:git branch

To create a branch:git branch <name>

To switch branches:git checkout <name>

Create + switch Branches:git checkout -b <name>

Merge a branch to the current branch:git merge <name>

To delete a branch:git branch -d <name>

git log --graph命令可以看到分支合并图

Add parameter-no-ff When merging means disable fast forward to see the branch log when viewing the log

When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;

When the work is not finished, first put the job site git stash , and then go to fix the bug, repair, and then git stash pop back to the job site

If you want to discard a branch that has not been merged, you can remove it by git branch -D <name> forcibly deleting the

  • View Remote library information, use git remote -v ;

  • Local new branches are not visible to others if they are not pushed to the remote;

  • Push branches from local, use git push origin branch-name , if push fails, first use git pull crawl remote new commit;

  • Local and remote branches corresponding to the branch, use git checkout -b branch-name origin/branch-name , local and remote branch names are best consistent;

  • Establishing the Association of local and remote branches, using git branch --set-upstream branch-name origin/branch-name ;

  • From the remote crawl branch, use git pull , if there is a conflict, you must first handle the conflict

    • The command is git tag <name> used to create a new label, either by default HEAD or by specifying a commit ID;

    • git tag -a <tagname> -m "blablabla..."Label information can be specified;

    • git tag -s <tagname> -m "blablabla..."Can be signed with PGP tag;

    • Command git tag to view all tags.

      • Command git push origin <tagname> to push a local tag;

      • Command git push origin --tags to push all the local labels that have not been pushed;

      • Command git tag -d <tagname> to delete a local tag;

      • Command git push origin :refs/tags/<tagname> to delete a remote label.

Git basic usage

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.