Skip to main content
Rollback to Revision 2
Source Link
Tom Prats
  • 7.8k
  • 9
  • 49
  • 80

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branchsome-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Wherewhere 'somesome-branch'branch can be replaced by any other branch
git branch base-branch -D  # Wherewhere 'basebase-branch'branch is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreatingrecreating branch with correct commits

Note: You can combine these all by putting &&&& between them.

Note 2Note2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3Note3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

ExampleEx:

git checkout feature-old  # Somesome branch with the extra commits
git log                   # Givesgives commits (write down the id of the ones you want)
git checkout base-branch  # Afterafter you have already cleaned your local copy of it as above
git checkout -b feature-new # Makemake a new branch for your feature
git cherry-pick asdfasd   # Wherewhere asdfasd is one of the commit ids you want
# Repeatrepeat previous step for each commit id
 
git branch feature-old -D # Deletedelete the old branch

Now feature-newfeature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Where 'some-branch' can be replaced by any other branch
git branch base-branch -D  # Where 'base-branch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreating branch with correct commits

Note: You can combine these all by putting && between them.

Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Example:

git checkout feature-old  # Some branch with the extra commits
git log                   # Gives commits (write down the id of the ones you want)
git checkout base-branch  # After you have already cleaned your local copy of it as above
git checkout -b feature-new # Make a new branch for your feature
git cherry-pick asdfasd   # Where asdfasd is one of the commit ids you want
# Repeat previous step for each commit id
 
git branch feature-old -D # Delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # where some-branch can be replaced by any other branch
git branch base-branch -D  # where base-branch is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # recreating branch with correct commits

Note: You can combine these all by putting && between them

Note2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Ex:

git checkout feature-old  # some branch with the extra commits
git log                   # gives commits (write down the id of the ones you want)
git checkout base-branch  # after you have already cleaned your local copy of it as above
git checkout -b feature-new # make a new branch for your feature
git cherry-pick asdfasd   # where asdfasd is one of the commit ids you want
# repeat previous step for each commit id
git branch feature-old -D # delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

Second iteration.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Where 'some-branch' can be replaced by any other branch
git branch base-branch -D  # Where 'base-branch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreating branch with correct commits

Note: You can combine these all by putting && between them.

Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Example:

git checkout feature-old  # Some branch with the extra commits
git log                   # Gives commits (write down the id of the ones you want)
git checkout base-branch  # After you have already cleaned your local copy of it as above
git checkout -b feature-new # Make a new branch for your feature
git cherry-pick asdfasd   # Where asdfasd is one of the commit ids you want
# repeatRepeat previous step for each commit id 

git branch feature-old -D # Delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Where 'some-branch' can be replaced by any other branch
git branch base-branch -D  # Where 'base-branch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreating branch with correct commits

Note: You can combine these all by putting && between them.

Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Example:

git checkout feature-old  # Some branch with the extra commits
git log                   # Gives commits (write down the id of the ones you want)
git checkout base-branch  # After you have already cleaned your local copy of it as above
git checkout -b feature-new # Make a new branch for your feature
git cherry-pick asdfasd   # Where asdfasd is one of the commit ids you want
# repeat previous step for each commit id
git branch feature-old -D # Delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Where 'some-branch' can be replaced by any other branch
git branch base-branch -D  # Where 'base-branch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreating branch with correct commits

Note: You can combine these all by putting && between them.

Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Example:

git checkout feature-old  # Some branch with the extra commits
git log                   # Gives commits (write down the id of the ones you want)
git checkout base-branch  # After you have already cleaned your local copy of it as above
git checkout -b feature-new # Make a new branch for your feature
git cherry-pick asdfasd   # Where asdfasd is one of the commit ids you want
# Repeat previous step for each commit id 

git branch feature-old -D # Delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branchsome-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # whereWhere some'some-branchbranch' can be replaced by any other branch
git branch base-branch -D  # whereWhere base'base-branchbranch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # recreatingRecreating branch with correct commits

Note: You can combine these all by putting &&&& between them.

Note2Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note3Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

ExExample:

git checkout feature-old  # someSome branch with the extra commits
git log                   # givesGives commits (write down the id of the ones you want)
git checkout base-branch  # afterAfter you have already cleaned your local copy of it as above
git checkout -b feature-new # makeMake a new branch for your feature
git cherry-pick asdfasd   # whereWhere asdfasd is one of the commit ids you want
# repeat previous step for each commit id
git branch feature-old -D # deleteDelete the old branch

Now feature-newfeature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # where some-branch can be replaced by any other branch
git branch base-branch -D  # where base-branch is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # recreating branch with correct commits

Note: You can combine these all by putting && between them

Note2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Ex:

git checkout feature-old  # some branch with the extra commits
git log                   # gives commits (write down the id of the ones you want)
git checkout base-branch  # after you have already cleaned your local copy of it as above
git checkout -b feature-new # make a new branch for your feature
git cherry-pick asdfasd   # where asdfasd is one of the commit ids you want
# repeat previous step for each commit id
git branch feature-old -D # delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

This won't fix branches that already have the code you don't want in them (see below for how to do that), but if they had pulled some-branch and now want it to be clean (and not "ahead" of origin/some-branch) then you simply:

git checkout some-branch   # Where 'some-branch' can be replaced by any other branch
git branch base-branch -D  # Where 'base-branch' is the one with the squashed commits
git checkout -b base-branch origin/base-branch  # Recreating branch with correct commits

Note: You can combine these all by putting && between them.

Note 2: Florian mentioned this in a comment, but who reads comments when looking for answers?

Note 3: If you have contaminated branches, you can create new ones based off the new "dumb branch" and just cherry-pick commits over.

Example:

git checkout feature-old  # Some branch with the extra commits
git log                   # Gives commits (write down the id of the ones you want)
git checkout base-branch  # After you have already cleaned your local copy of it as above
git checkout -b feature-new # Make a new branch for your feature
git cherry-pick asdfasd   # Where asdfasd is one of the commit ids you want
# repeat previous step for each commit id
git branch feature-old -D # Delete the old branch

Now feature-new is your branch without the extra (possibly bad) commits!

added 1 characters in body
Source Link
Tom Prats
  • 7.8k
  • 9
  • 49
  • 80
Loading
Source Link
Tom Prats
  • 7.8k
  • 9
  • 49
  • 80
Loading