Pagine

Thursday 25 May 2017

Stashing your changes with git

Git has a command that allows you to save the current state of the local working repository and go back to the last committed revision with git stash. This is really helpful when you have to develop an urgent fix. After this, you can restore the stashed changes and continue with your development.
To use this command, just execute the following command snippet:
$ git stash
Do your fix and then unstash edit:
$ git stash pop
Of course, you can do more with this command, such as save a list of stashes:
$ git stash
See the list of available stashes
$ git stash list
Apply the second stash
$ git stash apply stash@"1}
Delete a stash
$ git stash drop stash@"1}
Or delete all stashes
$ git stash clear
Let's suppose that your stash concerns a feature and you haven't created a dedicated branch for it. You can simply create a branch executing this command:
$ git stash branch mynewbranch
Remember this command is only for urgent fixes. If you want to add a new feature, you should use a new branch.

No comments:

Post a Comment