DEV Community

Discussion on: Git: Cheat Sheet (advanced)

Collapse
 
exadra37 profile image
Paulo Renato • Edited

Awesome article... congrats :)

My favourite and most used Git alias:

$ alias | grep wip -
gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"'

The gwip commits everything with the message --wip-- [skip ci]. By everything I mean untracked files, changes not staged for commit, and changes already staged for commit.

The gunwip reverts gwip, with the caveat that changes already staged for commit will become changes not staged for commit.

I use it to save my work until I am ready to create a proper commit.

Having [skip ci] in the commit message tell the Continuous Integration pipeline to ignore the commit.

Collapse
 
vfonic profile image
Viktor

This is a great idea! This functionality should probably be included within git.

One idea that comes to my mind how you could complicate this (read: make it work "completely"). You could extend the script to open all the staged files and add a comment to the top of the file. Something like: --staged--. Then, when you "unwip", it can read that comment and stage/unstage files as needed, while also removing that comment.

Collapse
 
tpenguinltg profile image
tPenguinLTG

It already is, in a way.

If you do a git stash -u, it will create a commit for you that includes staged, unstaged and untracked files, and it knows which files were staged and which ones weren't. If you wanted to keep the changes that were stashed as they were, you can issue a git stash apply immediately after (use apply to keep the stash, or pop to discard it after applying it).

Thread Thread
 
vfonic profile image
Viktor

This is amazing! Thank you!

Git never seizes to amaze me for its unlimited functionality.

For applying the stash, you need add --index as in: git stash apply --index. This will restore the index (staged/unstaged files) along with the file changes.