Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are those 'WIP' and 'index' commits that appear after stashing?

When I run git lg on my local development branch, the latest commit is shown as below:

* 7d21213 - (1 hours ago) update business rules - developer1 (HEAD, origin/develop, origin/HEAD, develop)

However, if I stash local changes by running git stash and then run git lg, I get the following:

*  at12334 - (13 seconds ago) WIP on develop: 7d21213 update business rules - developer1 (refs/stash)
|\
| * ef9a11b - (14 seconds ago) index on develop: 7d21213 update business rules - developer1
|/
* 7d21213 - (1 hours ago) update business rules - developer1 (HEAD, origin/develop, origin/HEAD, develop)

What does this mean? It seems that two new commits (labelled index and WIP) are created after stashing. Is that the case, and, if so, what is the logic behind such commits?


Note

git lg

is an alias already defined in the test environment as

git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)' --all
like image 410
clockworks Avatar asked Sep 24 '14 16:09

clockworks


People also ask

What is a WIP commit?

WIP Commit - convention for calling a temporary commit that is meant to be a temporary save point during the lifetime of a user story. Feature Branch - convention for calling a git branch that is used specifically to work on one user feature story.

What does stashing changes do in git?

git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on.

What does WIP mean in github?

git-wip is a script that will manage Work In Progress (or WIP) branches. WIP branches are mostly throw away but identify points of development between commits. The intent is to tie this script into your editor so that each time you save your file, the git-wip script captures that state in git.

What is WIP in stash?

From the git-stash documentation: A stash is by default listed as "WIP on branchname … ​", but you can give a more descriptive message on the command line when you create one. WIP stands for work in progress.


1 Answers

"WIP" is an acronym for Work-In-Progress. It is meant to suggest that you are temporarily saving the current state of your work even though you aren't at a natural stopping point.

Stashing saves your work in the repository using familiar commit/merge mechanisms. In particular, it is possible to view all currently stashed items in context by running gitk --reflog, although only the most recent stash will be labeled with stash. An important difference between a regular commit and a stash is that when stashes are removed (for example via git stash clear), they are no longer visible in the reflog and will therefore be more difficult to recover.

A stash is normally performed in two parts:

  1. An "index" commit is performed for anything that has been "add"ed since the last commit.
  2. The "WIP" commit is performed as a merge between the working state and the index commit.

If you haven't performed any add operations since the last commit, the index commit will be empty. However, even if the index is empty, it is still committed. The subsequent implicit merge can complicate things if you, for example, wanted to cherry-pick from a stash in order to avoid certain complications associated with git stash pop.


Git's stash mechanism is clever, powerful, and useful, but it is also complicated, error prone, and dangerous. My practice lately has been to avoid the use of git stash in favor of getting similar results with something like git commit -a -m "stash" to save my work and git reset HEAD~1 (after checking out the "stash" commit) to restore it.

This leaves the most useful application of git stash as just being a quick way to get rid of all local changes if you know that you no longer need them.

By the way, you can remove the "WIP" and "index" commits from your logs by running git stash clear -- but don't do that if you have valuable work saved only on the stash.

like image 145
Brent Bradburn Avatar answered Oct 06 '22 19:10

Brent Bradburn