Need help cleaning up git repository

Jan.Sommer at dlr.de Jan.Sommer at dlr.de
Thu Nov 5 14:40:44 UTC 2020



> -----Original Message-----
> From: users <users-bounces at rtems.org> On Behalf Of Peter Dufault
> Sent: Thursday, November 5, 2020 3:11 PM
> To: rtems-users at rtems.org <users at rtems.org>
> Subject: Need help cleaning up git repository
> 
> I'm not as good at "git" as I should be.  I'd like some help cleaning up my git
> repository so that I can submit some changes.
> 
> In particular when I got started I committed some changes to my local copy of
> master without branching it, and then started merging changes on other
> branches against that.  So my RTEMS repository looks like this:
> 
> [dufault at gen6 rtems]$ git branch -rv
>   origin/4.10   e3f6d35 cpukit/score: avoid NULL and races in priority mutex
>   origin/4.11   a100457 leon,gr1553b: improve init check
>   origin/4.8    48953df Remove (Obsolete).
>   origin/4.9    344856b rpc: misaligned address exception in get_myaddress.c
>   origin/5      7021c01 libfs/rfs: Check search bit map end on last bit
>   origin/HEAD   -> origin/master
>   origin/master 6823943 score: Fix unused parameter 'lock' warning
> 
> [dufault at gen6 rtems]$ git branch -v
>   add-uart-to-beatnik a3559e9 put rtems_shell_move_left() in correct file.
>   atsam-fixes         3926a46 Merge branch 'master' into atsam-fixes
>   master              34f0ccb [ahead 17] Merge branch 'master' of
> git://git.rtems.org/rtems
> * mvme5500-final      5f5f9c7 Merge branch 'master' into mvme5500-final
> 

Ok, I hope I understand everything correctly.
Still, best to make a local copy of your repository directory.

> You can see that my master is ahead of origin/master, and my local branches
> that I'd like to clean up (e.g. mvme5500-final, atsam-fixes) also include those
> changes.
> 
> I think I want to do something like:
> - Rename my local master branch to a branch name that is related to the
> changes I put in;

# Create a new branch from your local master branch under a new name
$ git branch NewBranchName master
# Reset the local master branch to be in line with origin/master (your changes will still be in NewBranchName)
$ git checkout master
$ git reset --hard origin/master

> - Drop the changes I made that on that branch in the other branches, e.g
> mvme5500-final, atsam-fixes etc so that those branches are now based on
> origin/master and only have the changes related to what I was working on.
> 

You might achieve that with a rebase in the respective branch, e.g. for mvme5500-final:
$ git checkout mvme5500-final
$ git rebase -i origin/master
This should open a terminal with all commits in this branch since origin/master with the oldest commit at the top.
Simply, delete the full lines of all the commits you don't want to keep in the branch, i.e. the one from your old master, save and close.
If you are lucky and no conflicts appear, you end up with a branch which is based on origin/master with only the commits you want.

Another option would be to create a new branch based on origin master and cherry-pick the commits you want to keep from mvme5500-final using git cherry-pick.
$ git branch mvme5500-new mvme5500-final
$ git checkout mvme5500-new
# Cherry-pick a single commit
$ git cherry-pick <commit hash>
# Cherry-pick a set of continuous commits
§ git cherry-pick <first commit>~..<last commit>  # make sure to have the "~" after the first hash

That's what I could come up with so far.

Best regards,

    Jan

> Any advice?
> 
> Peter
> -----------------
> Peter Dufault
> HD Associates, Inc.      Software and System Engineering
> 
> This email is delivered through the public internet using protocols subject to
> interception and tampering.



More information about the users mailing list