-1

I needed to use the file structure that someone had created locally and not yet published so I branched off of their branch using the command git checkout -b new_branch_name old_branch_name. Now their changes are published. When I raise a PR to publish my work I would like the PR to be clean and only contain my work

Would the solution be to commit all my changes, switch to master, pull all latest changes, merge master into my branch, and then the other person's commits will not show up anymore?

Cameron
  • 185
  • 2
  • 11
  • Are you asking how to delete a commit from your branch? Or are you asking if there's a way you can delete all the commits that match a certain set of criteria? – Andy Lester Mar 28 '22 at 20:09
  • @isherwood I needed to use the file structure that someone had created locally and not yet published so I branched off of their branch. Now their changes are published. When I raise a PR to publish my work I need the PR to be clean and only contain my work. – Cameron Mar 28 '22 at 20:16
  • @isherwood maybe the solution is to commit all my changes, switch to master, pull all latest changes, merge my branch with master, and then the other person's commits will not show up anymore? I am not sure? – Cameron Mar 28 '22 at 20:17
  • @AndyLester see more details above – Cameron Mar 28 '22 at 20:18
  • "Right now when I do a git log I see all the other persons changes in the commit history" Yes, because you branched from the other person's branch. What did you expect? – matt Mar 28 '22 at 20:32
  • Does this answer your question? [Update Git branches from master](https://stackoverflow.com/questions/3876977/update-git-branches-from-master) – isherwood Mar 28 '22 at 21:12

1 Answers1

2

Now their changes are published. When I raise a PR to publish my work I need the PR to be clean and only contain my work.

Do you mean that their PR has now been merged? Cool. So now you need to rebase your commits onto whatever the main branch is (the one that "their changes" got merged to). The form of that command is:

git rebase --onto <nameOfMainBranch> <SHAofCommitYouBranchedFrom> <nameOfYourBranch>
matt
  • 515,959
  • 87
  • 875
  • 1,141