Skip to main content
add --hard
Source Link
William Pursell
  • 209.4k
  • 48
  • 272
  • 307

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset --hard sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Note that you donotdo not really need to cherry-pick to set new-branch, and you could just as easily do:

$ git reset sha1-of-C

while you have new-branch checked out. This will actually give you R-A-B-C instead of R-A-B-C'. Note that the only difference between C and C' is the commit time.

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin, or store the history somewhere.

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Note that you donot really need to cherry-pick to set new-branch, and you could just as easily do:

$ git reset sha1-of-C

while you have new-branch checked out. This will actually give you R-A-B-C instead of R-A-B-C'. Note that the only difference between C and C' is the commit time.

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin, or store the history somewhere.

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset --hard sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Note that you do not really need to cherry-pick to set new-branch, and you could just as easily do:

$ git reset sha1-of-C

while you have new-branch checked out. This will actually give you R-A-B-C instead of R-A-B-C'. Note that the only difference between C and C' is the commit time.

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin, or store the history somewhere.

added 338 characters in body
Source Link
William Pursell
  • 209.4k
  • 48
  • 272
  • 307

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Note that you donot really need to cherry-pick to set new-branch, and you could just as easily do:


$ git reset sha1-of-C

while you have new-branch checked out. This will actually give you R-A-B-C instead of R-A-B-C'. Note that the only difference between C and C' is the commit time.

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin, or store the history somewhere.

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin.

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Note that you donot really need to cherry-pick to set new-branch, and you could just as easily do:


$ git reset sha1-of-C

while you have new-branch checked out. This will actually give you R-A-B-C instead of R-A-B-C'. Note that the only difference between C and C' is the commit time.

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin, or store the history somewhere.

Source Link
William Pursell
  • 209.4k
  • 48
  • 272
  • 307

You cannot get exactly what you want since there will be differences in the commits, but the content of the files will be as you want if you do:

$ git checkout master
$ git reset sha1-of-B  # set master back to B
$ git cherry-pick sha1-of-D   # set master to R-A-B-D'
$ git checkout -b new-branch sha1-of-B   # set new-branch to B
$ git cherry-pick sha1-of-C   # set new-branch to R-A-B-C'

Once you do the reset, you may have a hard time locating the sha1 hashes of the various commits (they are available from the reflog), so you may want to put tags on everything before you begin.