git in pills : git stash

Download Git in pills : git stash

Post on 17-Jan-2017

199 views

Category:

Technology

2 download

Embed Size (px)

TRANSCRIPT

  • federico.panini@fazland.com - CTO

  • Git in PillsGIT Stashing

    federico.panini@fazland.com - CTO

  • Git-Stashsave your work during work :)

    federico.panini@fazland.com - CTO

    The problem

    When your working on a ticket to solve a bug or to implement a new feature, frequently happens that you need to switch to another branch for solving a problem that has occurred. So what to do ? Your actual work is in a messy state you have new files, uncommitted ones

  • Git-Stashsave your work during work :)

    federico.panini@fazland.com - CTO

    You could commit your amends and switch to the other branch for solve a bug:

    DONT DO IT!

    Youll loose all of the informations about your progress and also youre storing a commit with inconsistent code.

  • Git-Stashsave your work during work :)

    federico.panini@fazland.com - CTO

    How can I leave the state of my current branch clean, and switching to another branch ?

    use GIT STASH

    Using git stash will allow you to maintain the dirty state of your current working directory and saves it on a stack of unfinished changes that you can reapply at any time.

  • Git-Stashhow to use it ? - stash p. 1

    federico.panini@fazland.com - CTO

    Stashing your current files is easy and simple: in your directory where messy files are type:

    $ git status# On branch feature/610_i18N_de_ro# Changes to be committed:# (use "git reset HEAD ..." to unstage)## modified: routing_de.yml# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php## Changes not staged for commit:# (use "git add ..." to update what will be committed)## modified: scripts/crontab#

    Youll see a list of unstaged files.

  • Git-Stashhow to use it ? - stash p. 2

    federico.panini@fazland.com - CTO

    Stashing your current files is easy and simple: in your directory where messy files are now type:$ git stashSaved working directory and index state \ "WIP on feature/610_i18N_de_ro: 049d078 added the index file"HEAD is now at 049d078 added the index file(To restore them type "git stash apply")

    Now your working directory is clear

    $ git status# On branch feature/610_i18N_de_ronothing to commit, working directory clean

    at this point you can freely switch to another branch do whatever you need to do to fix bugs or implement new feature

  • Git-Stashhow to use it ? - stash p. 3

    federico.panini@fazland.com - CTO

    Where are your stashed files now ?

    $ git stash liststash@{0}: WIP on feature/610_i18N_de_ro: 049d078 added the index filestash@{1}: WIP on feature/610_i18N_de_ro: c264051 Revert "added file_size"stash@{2}: WIP on feature/610_i18N_de_ro: 21d80a5 added number to log

    You can see a list of stashes and the first one (stash{0}) is the last that you created. At any time you can get the stash back.

  • Git-Stashhow to use it ? - stash p. 4

    federico.panini@fazland.com - CTO

    How to stash back your files ?

    $ git stash apply --index# On branch feature/610_i18N_de_ro# Changes to be committed:# (use "git reset HEAD ..." to unstage)## modified: routing_de.yml# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php## Changes not staged for commit:# (use "git add ..." to update what will be committed)## modified: scripts/crontab#

    When your critical bug fixing is done you can get the files back from the stash and continue you development on that files

  • Git-StashBEST PRACTISES - stash message

    federico.panini@fazland.com - CTO

    If you dont give a message comment to a stash git automatically creates it taken it from the last commit log message. This could be a bit confusing when your working with multiple stash and could lead to errors huge errors! So the adivice is to use git stash save message. This command is equal to git stash with the difference that you can give a message name to the stash

    $ git stash save stash fiels for #610 working progress on upload image bug fixing # On branch feature/610_i18N_de_ro# Changes to be committed:

  • Git-StashBEST PRACTISES - stash lifetime p.1

    federico.panini@fazland.com - CTO

    Git Stash is used for switching quickly between branches when you have to work on multiple different tasks, or when suddenly you have to fix a critical bug. Considering that the stash is shared between all the git repository it is not absolutely advised to leave the code in the stash for a long period. The stash is a quick knife tool which will help you with sudden code events.

  • Git-StashBEST PRACTISES - stash lifetime p.2

    federico.panini@fazland.com - CTO

    If you plan to work on a new feature for a long time period, instead of putting the working files your on in the stash you can create a branch for them:

    BRANCH IT!

    $ git stash branch testchangesSwitched to a new branch "testchanges"# On branch testchanges# Changes to be committed:# (use "git reset HEAD ..." to unstage)## modified: routing_de.yml# modified: src/Fazland/WebsiteBundle/Controller/QuoteController.php# modified: src/Fazland/WebsiteBundle/Controller/SettingsController.php## Changes not staged for commit:# (use "git add ..." to update what will be committed)## modified: scripts/crontab#Dropped refs/stash@{0} (f0dfc4d5dc332d1cee34a634182e168c4efc3359)

  • Git-Stashdropping a stash

    federico.panini@fazland.com - CTO

    When your stash has been got back you can delete it. Remember that its always a best practice to delete your stash just after you got back from stash stack.

    $ git stash drop stash@{0}Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)

  • Git-StashCommand reference

    federico.panini@fazland.com - CTO

    git stash list git stash git stash save message git stash apply index git stash drop stash{n} git stash branch branchname

  • Git-StashReference

    federico.panini@fazland.com - CTO

    http://git-scm.com/book/en/v1/Git-Tools-Stashing https://www.kernel.org/pub/software/scm/git/docs/git-stash.html http://gitready.com/beginner/2009/01/10/stashing-your-changes.html

    http://git-scm.com/book/en/v1/Git-Tools-Stashinghttps://www.kernel.org/pub/software/scm/git/docs/git-stash.htmlhttp://gitready.com/beginner/2009/01/10/stashing-your-changes.html