DEV Community

Vasudevan Tamilarasan
Vasudevan Tamilarasan

Posted on

Git commands: Part-3

Payilagam - Day - 07: 21-Feb-2024

Topic: Git Commands: Part-3

  1. git cherry-pick <commit_id>

This command is used to transfer a specific commit between the branches.

Example scenario:

In main branch a file contains a hello world program.

We create a new branch, and modified the same file twice (i.e, a java program & and a c++ hello world program.

We commit these changes, and all settled.

Then if we want the java program specifically in the main branch but not the latest version of the file, then we use this cherry-pick command.

It merge the specific commit to the current branch.

  1. git stash

    This command acts like as temporary storage for saving the tracked files.

    After performing the git stash command, git stores all the un-commited files & information (both staged and un-staged) in a stash, hence we can switch out branches and getting back to out branch to complete the modification and then we can commit.

    Git doesn't allow us to switch branch, if we have any un-committed modification in out b

    After sometime, if we want the changed(tracked) files back, we are able to retrieve those changes from the stash area.

    when we perform the git stash list :

        It shows the tracked changes by the insertion order like:
    
                 stash@{0}: WIP on main: 2626dd3 adding a c program
                 stash@{1}: WIP on Payilagam: 59ae5b8 checking for git merge in payilagam branch
    
        these information are denote the insertion order & respective commit messages to identify which version of the file is to we pointed.
    
  2. a) git stash pop

    It retrieve the file present in the top of the stash limit and we can commit those files.

  3. b) git stash pop

    It retrieve the specified indexed file from the stash list for committing.

Top comments (0)