Tuesday, June 23, 2015

p4 shelve equivalent in Git with an example

The equivalent of p4 shelve on GIT is stashing.

Say I have modified the file on my repository and I see the following:
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   vimrc
no changes added to commit (use "git add" and/or "git commit -a")
Now to shelve these changes, 
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git stash
Saved working directory and index state WIP on master: 80e892a Track git aliases.       modified:   generic_aliases
HEAD is now at 80e892a Track git aliases.

You can check the shelving is done by:
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git stash list
stash@{0}: WIP on master: 80e892a Track git aliases. modified: generic_aliases
Here the shelved change is identified by: stash@{0}. 

You can re-apply the change by:
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git stash apply
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   vimrc
no changes added to commit (use "git add" and/or "git commit -a")
Which can be verified by:
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   vimrc
For more details read more about git stash.

0 comments:

Post a Comment