How GIT switches branches without committing commits

Source: Internet
Author: User

Recently encountered a problem, things are like this, just received a customer said his project has a problem, so open the local source view after the troubleshooting to determine the problem, and then began to fix the problem to get ready to commit to git to find the current branch is not right, But the problem is that I have made a lot of changes in the current branch, and if you want to switch branches, you must first commit the modified files. So now the question is: how do I switch branches without committing a commit? Finally, see the pro git documentation to learn that there is a stash feature in Git that allows 6.3 storage (stashing)Source: <http://git.oschina.net/progit/6-Git-%E5%B7%A5%E5%85%B7.html#6.3-%E5%82%A8%E8%97%8F%EF%BC%88Stashing%EF%BC%89 >

Often something like this happens when you're working on a part of the project, where things are in a messy state, and you want to move on to other branches to do some work. The problem is that you don't want to commit half of the work, or you won't be able to get back to this work point later. The way to solve the problem is to git stash order.

"Storage" can get the middle state of your working directory-that is, your modified tracked files and staged changes-and save it to a stack of unfinished changes that can be re-applied at any time.

because I haven't used this feature before, I did a test. FirstModify the Test2.txt file in the test branch firstAfter the modification is completed, it is found that the modification should not be in the test branch, so all changes are stored first (stash) and then switched to the corresponding branch (new Test2 Branch) and remove the previous modifications from the stash and then test2 all the changes in the branch because the storage will generate two branch records, so the commit history looks messy, so the previous storage branch deleted (after the deletion of clean and good) complete, merging branches and other operations

Using the Stash's branch chart
Commit history reference after deleting stash: Git storage (stashing) when Git switches branches, does it need to commit the currently modified



From for notes (Wiz)



How GIT switches branches without committing commits

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.