Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 324
Rwky Avatar asked Oct 17 '10 13:10

Rwky


People also ask

Should I commit before or after pull?

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched. Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

Can I git commit without add?

Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.


1 Answers

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.

like image 124
rfunduk Avatar answered Sep 29 '22 08:09

rfunduk