What's the best way to have a "temporary" commit in git?

Rwky picture Rwky · Oct 17, 2010 · Viewed 26.1k times · Source

Say I have a project with two branches master and dev. I have a bunch of commits on dev for a special event which once tested are merged into master. Then after the event is over I want to remove the event specific code. However a git reset won't do since other commits have been made since the event code was added.

Currently I use git checkout to checkout the files from before the event was merged in and then use git diff to re-add in the changes that have been made since the event was committed. This seems like a very messy method to me.

Does anyone have a better solution for having temporary code in a project?

Edit: To be clear the changes need to be committed, pushed, uncommitted, pushed.

Answer

rfunduk picture rfunduk · Oct 17, 2010

Take master and create a branch: git checkout -b special-event, make/apply your changes. Once the event is over, simply switch back to master and abandon/delete the branch.

In order to continue making changes, make them on master and merge them into the special branch as you go. git checkout master ... make changes ... git checkout special-event; git merge master.

Alternatively, make all your special-event related changes in one commit, then use git revert when you want to roll them out and specify just that commit.