Git stash and git cherry-pick

Source: Internet
Author: User

From: http://blog.csdn.net/qinjienj/article/details/7475890

 

Developers often encounter this situation: it takes a few days to create a new function, and has changed more than a dozen files. Suddenly, a bug needs to be solved urgently, and then a build test group is given. Before the advent of git, manual backup was basically required, which was time-consuming and error-prone.

In short, the GIT stash command is used to help developers temporarily shelve the changes they have made, roll back to the status before the changes, and perform other necessary operations (such as publishing, solving a bug, or branch, and so on. You can reload the changes that were put on hold later. Is it cool?

First, use git add to add all the changes to the staging area.

Git add.

Use git stash to put these changes on hold.

Git stash

------------

Git stash save "what you want to say"

 

------

 

At this point, the current work platform will reply to the change. What should I do? 10 thousand words are omitted here.

Need to retrieve the changes that were previously shelved and continue the previous work?

Git stash apply.

You can also use git stash list to view all the shelved versions (it may have been shelved many times, so it is better not to do this, it is easy to confuse)

When a stack is shelved, for example, if you want to retrieve the 2nd stacks, you can use git stash apply stash @ {1}

If you want to retrieve 1st, you can use git stash pop

If you want to delete a stash, git stash drop <ID>

Delete all stash and git stash clear

 

 

_____________________________________________________________________________________________

 

Actual problems:
A commit (38361a68138140827b31b72f8bbfd88b3705d77a) is created on the local master branch. How can I place it on the local old_cc branch?

One way: Use cherry-pick. According to the GIT documentation:

Apply the changes introduced by some existing commits

Is to apply an existing commit (can be understood as submitting again)

Simple usage:

Git cherry-pick <commit ID>

 

For example:
$ Git checkout old_cc
$ Git cherry-pick 38361a68 # The 38361a68 number is located:

 

$ Git log

Commit 38361a68138140827b31b72f8bbfd88b3705d77a
Author: Siwei Shen <siwei.shen@focusbeijing.com>
Date: Sat Dec 10 00:09:44 2011 + 0800

1. if it succeeds, it will be submitted normally. Result:

Finished one cherry-pick.
# On branch old_cc
# Your branch is ahead of 'origin/old_cc 'by 3 commits.

2. If there is a conflict in the cherry-pick Process

Automatic cherry-pick failed. After resolving the conflicts,
Mark the corrected paths with 'git add <paths> 'or 'git Rm <paths>'
And commit the result:

Git commit-C 15a2b6c61927e5aed6718de89ad9dafba939a90b

As with normal conflicts, manually solve them:
2.1 $ git status # Check which files conflict

Both modified: APP/models/user. Rb

2.2 $ Vim APP/models/user. RB # solve it manually.
2.3 $ git add APP/models/user. Rb
2.4 git commit-C <New commit number>

 

 

 

 

 

 

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.