1

Say I created a feature-x branch and merged or rebased with master branch. Now in future is it possible to remove all the changes I added through feature-x branch through git?

This is is a common feature where we add some updates for a limited amount of time and remove it then. Can some one help if it is possible with git.

Thanks in advance.

I will get more clearer with an example. Suppose I added a poll script in feature-x branch and rebased it with master branch which I use as production branch. I may use the poll script only for say 1 month. In between I made several commits, rebased new branches with master branch. Now after 1 month, I want to remove that poll script completely from the master branch but keeping all the new changes(new commits) in the master branch.

0

4 Answers 4

1
man git-revert

git revert will replay a commit in reverse.

2
  • thanks for your reply... but git revert will undo all the recent commits I have made
    – user434509
    Commented Jan 9, 2012 at 16:10
  • @user434509: It won't - git revert f00 creates a new commit that just reverses the change introduced by commit foo. Commented Jan 9, 2012 at 16:36
1

Well you can use git revert to undo commits. This will create a new commit which basically undoes the changes of the old commit. Or you can use git rebase to remove commits from the history. However that should not be done on a shared repository, since it will rewrite the history, so if someone has checked out before the rewrite and now pulls he/she is likely to get horrible merge conflicts

2
  • thanks for your reply... but git revert will undo all the recent commits I have made
    – user434509
    Commented Jan 9, 2012 at 16:10
  • @user434509: No you can tell git revert which commits to revert (and only those)
    – Grizzly
    Commented Jan 9, 2012 at 17:44
0

Would it be possible to, instead of merging/rebasing your feature branch into master, just using the feature branch as your production code, merging master into it as necessary? Then, when you are done with your feature branch, go back to using master as the production code.

If I understand git rebase correctly, it doesn't store any information about the common ancestor of the two branches, so it would be difficult to separate the two again. I can't comment on the use of git revert to undo a merge commit, other than to say it sounds right.

1
  • Yes that is one option... but here I have to change the code again... then pull changes from master branch and then rebase it with the master again. I was looking for something where I don't need to touch the code again and do the necessary changes through git.
    – user434509
    Commented Jan 9, 2012 at 16:09
0

For a workflow that enables what you are doing out of the box, see here:

https://plus.google.com/109096274754593704906/posts/R4qkeyRadLR

The building of release candidates and making relentless use of rerere will help you get this going.

It's easier for you to create a new branch right now and redo the merges you did before, leaving out the unwanted one. You may need to rebase a few of them. To "rescue" the master branch right now looks like too much effort.

Not the answer you're looking for? Browse other questions tagged or ask your own question.