Git learns git operations Advanced (branching, merging, checking different)

Source: Internet
Author: User
Tags commit diff

> #git add-i

Interactively add the workspace code to the local code buffer

> #git add-p

The option y/n/a/d/e appears

If you select Y to add the workspace code to the local code buffer, select N or D to terminate the commit operation, select a to add

How to submit code to a central warehouse

1.> #git Add Some-file

#git commit-m "Some word"

Useful when adding simple annotations

2. # git commit-m "Some word"-a

Submit all locally changed code to the Central Library

3 # git commit-m "some word" some-file

Submits the file with the specified file name to the Central Library


View different

#git diff

Results show that the local workspace has not yet been committed to the buffer

#git diff--cached

The display buffer differs from the central warehouse

#git diff HEAD

Compare local workspaces to buffers and central warehouses


File Rename and move

#git MV Index.html hello.html

The file name was modified

Changes need to be submitted after modification

#git commit-m "Rename index.html"


Understanding and using branching

#git branch-m Master MyMaster

#git Branch

Modified the name of master to MyMaster

#git Branch Newbranch

A Newbranch branch was created, but at this point the working branch is still master and you need to go to git chekout newbranch before switching branches.

The following command allows you to switch branches while creating a branch

#git Checkout-b Another Master

This generates a another branch from the master branch and switches the branch to another.

#git branch-a

Show all branches on local and remote

Delete Branch

#git branch-d Branch-name

Branch Rename

#git branch-m Orgin-name New-name


Transfer changes between branches

The transfer is divided into three types:

1.Straight Merging

Check out a work branch

#git Checkout Master

Transfer the branch to commit to the current branch

#git Merge Alternate

Alternate for the branch to be merged into master

This method will deposit all log information in the alternate into master


2.squashing commits

There are two branch master branches and a contact branch

Merge contact into Master

#git Checkout Master

#git Merge--sqush Contact

Also need to execute git commit-m "" after committing changes

This submission will lock the log information of the contact into a one-time commit log.

3.cherry-pick Commit

This is a method of merging by submitting a name, you can merge only once or specify a single commit

#git Checkout Contact

Check out a branch

#git commit-m "Add Something"

The submission message will appear if the submission number is: 321d76f

We can use this number to sync this commit to another branch.

#git Checkout Master

#git Cherry-pick 321d76f

This execution process git has executed a commit process.

What if we have to submit a direct submission at some point?

#git Cherry-pick-n 321d76f

By adding the-n parameter, git commits the change to the cache without committing the commit

After you've modified the others, you can commit together.

#git Commit


Restore change

#git Reset--hard HEAD

The last commit process can be removed




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.