Re: Rebase

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2025-01-19 at 05:29:09, Al Grant wrote:
> Hello,
> 
> I am looking for some assistance rebasing please.
> 
> I have a feature branch which has the many recent commits and a main
> branch which has not had a commit for a long time. I want to make the
> code in the feature branch the code in the main branch.
> 
> I think a rebase is the command I need, but the exact steps I am not sure of.
> 
> I did try this:
> 
> 1. Sync both branches with remote (github)
> 2. git checkout feature
> 3. git rebase main

If you just want to make the branches completely identical, you can do
this:

----
$ git checkout feature
$ git update-ref refs/heads/main $(git rev-parse --verify refs/heads/feature)
----

That will make `main` the exact same commit as `feature`.  Note that you
don't want to be on the destination branch (in this case, `main`) when
you do the `git update-ref` call because that will result in the index
being out of sync with the commit.

You could also do this:

----
$ git checkout main
$ git reset --hard feature
----

That will update `main` and the working tree to be completely identical
to `feature`.  Please note that it will also completely and
irrecoverably destroy changes in any modified files in the working tree,
so you may prefer the first option, which is a little safer.

In either case, if there are changes in the `main` branch which are not
in the `feature` branch, this will remove them.  What I gave you above
will make them completely identical in every way, including in terms of
history.

If you want to preserve some of those changes, then you do need a
rebase, and the commands you gave are correct.  You will then need to
resolve the merge conflicts in each conflicting commit and continue the
rebase each time.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux