0

disclaimer: I am relatively new to Git so this may seem to be a confusing question from the title, so apologies in advance.

While working on a project I had created 2 branches (lets name them b1 and b2). b1 was created to define a specific translation file, whereas b2 was responsible for implementing that file in the project.

During my work, I failed to realize that the work was to be divided into 2 branches, and so defined the file, as well as implemented it in the same branch and later commit the changes to the repository (We are required to make only one commit per branch, therefore the solution here is not applicable for me)

One naive solution could be to copy everything again to the other branch manually and remove the unrelated files from the branch b2, as well as delete unrelated files from b1, and then amend the commit at b1, but there are too many files that would need to be copied and deleted manually. Is there a cleaner solution to this? If so what are the steps needed to achieve this?

Thanks in advance!

Muhammad Hamza
  • 823
  • 1
  • 17
  • 42
  • 1
    You could merge the branches, then soft reset, which would keep the changes in the index. This way you could unstage anything you didn't want and commit what you did. This won't merge the branches however. https://stackoverflow.com/questions/4315948/git-partial-merge-not-whole-branch – evolutionxbox Dec 24 '18 at 09:28
  • The "one commit per branch" requirement is silly. Branches—or more precisely, branch *names* —are essentially meaningless in Git; what matters are *commits*. The commits form branch-y and merge-y *structures* and these also matter. The names don't. See https://stackoverflow.com/questions/25068543/what-exactly-do-we-mean-by-branch – torek Dec 24 '18 at 10:54

1 Answers1

1

I would suggest branching b2 off b1. that way, b2 will have your implementation and the translation file. now you can just delete the translation file while keeping the implementation file.

you can do this:

git checkout b1

and then:

git checkout -b b2 #this will lead to b2 branching off from b1
AppleCiderGuy
  • 1,249
  • 1
  • 9
  • 16