0

I have a git branch called shared_pictures_feature. This branch has a bunch of new files that allows users to upload photos, share photos among friends, and rate photos. To ease my fellow developer's sanity during a code review, I want to break the shared_pictures_feature branch into three separate branches for PR review.

Each branch should only contain the relevant files I need for a particular sub-feature. For example, the upload_photos_feature branch should only contain code from the shared_pictures_feature that deals with uploading photos. Here's my question, how do I do this with git? Is this even possible?

thank_you
  • 11,001
  • 19
  • 101
  • 185
  • how would git have any notion of how your code is structured? Did you check in each individual "piece" into their own separate commits? Or it's all jumbled together? – Kritner Nov 16 '16 at 17:43
  • Follow-up quesiton to what @Kritner just said, is your code separated by directories? It seems almost like you are saying each relevant section of code is separated by directories, but I might be reading wrong. – Holden Lewis Nov 16 '16 at 17:45
  • I easily know which files should go into each feature. All changes in my `shared_pictures_feature` are related to new files. I'm hoping there could be some way that I can decommit all of the new files from my shared_pictures_feature branch and pick what files I want to pushed for pull request. – thank_you Nov 16 '16 at 17:45
  • So, just to clarify, you won't need to split an individual file into separate branches? – Holden Lewis Nov 16 '16 at 17:47
  • Absolutely not. No splitting of an individual file. Each feature is modular and does not share files among one another. – thank_you Nov 16 '16 at 17:49
  • You're looking for an interactive rebase: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History – bcmcfc Nov 16 '16 at 17:51
  • be careful of time paradoxes. Don't want to become your own grandfather – Kritner Nov 16 '16 at 17:56

1 Answers1

1

There are a few different ways to do this, but here is what I would suggest.

First, create and switch to your first branch.

git checkout -b upload_photos_feature

Next, find the commit where you branched shared_pictures_feature off of. I would suggest reading this StackOverflow question for details on how to do that. Then, in order to uncommit all of your files in that branch, you will want to do:

git reset --mixed <parent commit of both branches>

The next step will be to commit the relevant files. Just add and commit the files that you want in your upload_photos_feature branch, leaving the rest untouched.

Now, you will want to switch back to your original branch and restore the state you were in before.

git reset --hard HEAD
git checkout shared_pictures_feature

Now, you will want to go through those steps again for each new branch. Just make sure that you do the first step of creating the new branch each time since you don't want to lose anything on shared_pictures_feature.

Community
  • 1
  • 1
Holden Lewis
  • 387
  • 3
  • 18