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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With