Introduction to Git Branch tool

Source: Internet
Author: User
Tags commit

First, the basic action

The branch in Git is actually just a checksum containing the object (40 character length SHA-1 string)

files, so creating and destroying a branch becomes very inexpensive.

How does Git know what branch you are currently working on? In fact, the answer is also very simple, it holds a

A special pointer called head.

Create: Git branch iss53

Delete: Git branch-d iss53

Toggle: Git Checkout iss53

Create and toggle: Git checkout-b iss53

To see which branches have been merged into the current branch: Git branch--merge or vice versa: Git branch--no-merged

Second, the switch branch must follow the state

You can switch branches only in the following states:

1, all files in the current branch have been committed to the local version library.

2, the current has not submitted documents for storage, to ensure that the working directory is clean after the branch can be switched.

The main orders for storage are:

git status
# on branch Test
# Changes don't staged for commit:
#   (use "Git add <file> ..." to update wh At'll is committed
#   (use "Git checkout-<file> ..." to discard changes in working directory)
#
#   Modified:   b.txt
#   modified:   mx
#
No changes added to commit (use "git" add "and/or" Git commit-a ")

After you execute git stash

git stash
Saved working directory and index state WIP in test:32211b0 add B.txt head are now at
32211b0 add b.tx T
git status
# on branch Test No to
commit (working directory clean)

To view existing storage, you can use Git stash list:

git stash list
stash@{0}: WIP on test:32211b0 add B.txt

You can reapply the storage you just implemented, using the command that was previously prompted in the help output from the original stash command: Git stash apply. If you want to apply earlier storage, you can specify it by name, like this: Gitstash apply stash@2. If you do not specify, Git defaults to using the most recent storage and tries to apply it.

git stash apply
# on branch Test
# Changes don't staged for commit:
#   (use "git add <file> ..." to UPDA Te what'll be committed)
#   (use "Git checkout-<file> ..." to discard changes in working directory)
#
#   Modified:   b.txt
#   modified:   mx
#
No changes added to commit (use "git add" and/or "Git commit-a")
git stash list
stash@{0}: WIP on test:32211b0 add B.txt

You can see:

The Apply option only attempts to apply the stored work-the contents of the storage are still on the stack. To remove it, you can run

git stash drop, plus the name of the storage you wish to remove:

git stash Drop stash@{0}

Dropped stash@{0} (2bb9fe1993cf55843152025ae2bd79d5f7d8974c)

You can also run Git stash pops to reapply the storage and immediately remove it from the stack.

Author: 51cto Blog phper-a little bit every day

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

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.