You are not logged in.

#1 2023-04-27 10:10:49

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,142

[Solved] how to clean branch in git fork without deleting&recreating ?

Although I have been using git for AUR since it switched to git it still feels like a pitch black box to me.

Currently I'm the author of an open MR[1]  for mesa. Three changes are needed, each with their own commit.
Those changes are in a branch of a fork and are close to being suitable for merging.  Unfortunately the branch lists 20 commits instead of 3 .

I've tried git rebase and while this updated the branch it increased  the number of commits in the branch instead of decreasing them.

I have the 3 commits as external patches and they apply cleanly to latest mesa trunk.
I'd like very much to get rid of those addtional 17 unnecessary commits in the branch but the only way I found that works is to delete the branch and create a new one .

Does anyone know a better way ?




[1] https://gitlab.freedesktop.org/mesa/mes … ests/22443

Last edited by Lone_Wolf (2023-04-28 10:37:49)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#2 2023-04-27 11:11:30

3beb6e7c46a615a
Member
Registered: 2021-03-27
Posts: 165

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

Sounds like you're looking for "git rebase --onto"?  I.e. "git rebase --onto $desired_target_branch $first_commit_of_yours", so in your case probably "git rebase --onto main HEAD~2"?

Offline

#3 2023-04-27 12:25:23

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,142

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

Using --onto gave this result :

 Merge details

    The source branch is 4 commits behind the target branch
    27 commits will be added to main.
    Source branch will be deleted.

    Closes issue #7742 

Again, the number of commits added to main increased .

All i want is to have the 3 relevant commits in my branch and everything else just in origin/main so it is a 1:1 copy of upstream/main .
I don't see any reason why synchronising origin/main to the latest version of upstream/main should affect my branch at all.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#4 2023-04-27 12:56:54

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,561
Website

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

Sounds like you want to rewrite history and/or squash commits. Perhaps this link will help: https://git-scm.com/book/en/v2/Git-Tool … ng-History


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2023-04-27 14:09:04

3beb6e7c46a615a
Member
Registered: 2021-03-27
Posts: 165

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

I don't know what you did (showing the exact commands and the commits they touch would've been helpful) but the current state of your branch (I just cloned it) definitely doesn't look like you rebased:

*   Commit: bbf6ffd5c12ec75b2a32d80d39377f0edab2fcea (HEAD -> fix-microsoft-clc, lonewolf/fix-microsoft-clc)
|\  Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | Date:   2023-04-27 14:08:55 +0200 (2 hours ago)
| |
| | Merge branch 'fix-microsoft-clc' of https://gitlab.freedesktop.org/Lone_Wolf/mesa into fix-microsoft-clc
| |
| *   Commit: 119b87e218c6473804e367228cd1ee3bc99ccc9f
| |\  Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | | Date:   2023-04-27 09:28:18 +0200 (7 hours ago)
| | |
| | | Merge branch 'fix-microsoft-clc' of https://gitlab.freedesktop.org/Lone_Wolf/mesa into fix-microsoft-clc
| | |
| | *   Commit: 38da4c0883b4612a7862d957cdfe02362d716739
| | |\  Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | | | Date:   2023-04-27 01:01:10 +0200 (15 hours ago)
| | | |
| | | | Merge branch 'fix-microsoft-clc' of https://gitlab.freedesktop.org/Lone_Wolf/mesa into fix-microsoft-clc
| | | |
| | | * Commit: 18388c06f241f2d0fb2938ec10db7391e6fc44ed
| | | | Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | | | Date:   2023-04-25 13:44:57 +0200 (2 days ago)
| | | |
| | | | clc: Add clang frontendhlsl module to fix build of microsoft-clc with llvm 16+
| | | | Cc: mesa-stable
| | | |
| | | * Commit: fe8f9c9c89e0629a1cf6131c2e9a6c3957a503cd
| | | | Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | | | Date:   2023-04-25 13:39:42 +0200 (2 days ago)
| | | |
| | | |     clc: Add clangASTMatchers to fix static llvm build of microsoft-clc with LLVM 16+
| | | |     Cc: mesa-stable
| | | |
| | | * Commit: 9635cf69680769374d7d5c74a3a53f61b0984350
| | | | Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| | | | Date:   2023-04-12 22:04:35 +0200 (2 weeks ago)
| | | |
| | | | compiler/clc: Fix embedded clang headers (microsoft-clc) for LLVM 16+
| | | | Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
| | | | Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7742
| | | | Cc: mesa-stable

If you did rebase the three relevant commits on top of the upstream mesa branch you'd definitely not have any of these merge commits.  And the diff count doesn't just contain three commits ahead of main either:

$ git rev-list --left-right --count main...fix-microsoft-clc
11      198

I guess those three commits with your user name are the relevant ones? So what you want to do then is the following (first command will throw away all uncommitted changes, so make sure your copy is clean):

$ git reset --hard 18388c06f241f2d0fb2938ec10db7391e6fc44ed
$ git rebase --onto main HEAD~3
$ git push --force-with-lease

Then your log looks proper and the count matches up ("l" is my personal log alias, but you get the idea):

$ git l
* Good "git" signature for sebastian@swsnr.de with ED25519 key SHA256:xBUrqiiYS+mY5fCndm8Ye+SDU3Gr578hRbUL7ZzHbiY
| Commit: 8c39f0bf5ce73ee855febc9bba5f3ab304a696c3 (HEAD -> fix-microsoft-clc)
| Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| Date:   2023-04-25 13:44:57 +0200 (2 days ago)
|
| clc: Add clang frontendhlsl module to fix build of microsoft-clc with llvm 16+
| Cc: mesa-stable
|
* Good "git" signature for sebastian@swsnr.de with ED25519 key SHA256:xBUrqiiYS+mY5fCndm8Ye+SDU3Gr578hRbUL7ZzHbiY
| Commit: 33f91cf7ddcc18e0c324e400ead828335214320e
| Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| Date:   2023-04-25 13:39:42 +0200 (2 days ago)
|
|     clc: Add clangASTMatchers to fix static llvm build of microsoft-clc with LLVM 16+
|     Cc: mesa-stable
|
* Good "git" signature for sebastian@swsnr.de with ED25519 key SHA256:xBUrqiiYS+mY5fCndm8Ye+SDU3Gr578hRbUL7ZzHbiY
| Commit: fbc9fdf6578a9eabd541626edd773e49212b2dae
| Author: Lone_Wolf <lone_wolf@klaas-de-kat.nl>
| Date:   2023-04-12 22:04:35 +0200 (2 weeks ago)
|
| compiler/clc: Fix embedded clang headers (microsoft-clc) for LLVM 16+
| Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
| Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7742
| Cc: mesa-stable
|
* Commit: 7508f4b4b6dd309ccbc3275e59ca5859eeb89801 (origin/main, origin/HEAD, main)
| Author: David Heidelberg <david.heidelberg@collabora.com>
| Date:   2023-04-26 11:43:56 +0200 (28 hours ago)
|
| pvr: drop unused variable
|
| Fixes: 71fe789d354d ("pvr: Support ipf_creq_pf in pvr_isp_ctrl_stream()")
|
| Reviewed-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
| Signed-off-by: David Heidelberg <david.heidelberg@collabora.com>
| Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22709>
|
$ git rev-list --left-right --count main...fix-microsoft-clc
0       3

And do read Git's documentation… this isn't exactly the deep dark arts of Git, but a fairly straight-forward feature branch workflow.  Like git or not, it's a level of Git knowledge you'll need when you contribute to larger Git projects.

Offline

#6 2023-04-27 16:37:36

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,142

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

Thanks for the info, but everything I did try made things worse instead of better.

For now I gave up and have deleted the branch with the changes.

I will look for documentation about the fork-branch workflow and maybe try again in a few days. Incase I can't rise above the level of copy/pasting git commands without truly understanding them I'll stick to writing patch files and leave authoring MRs to others.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#7 2023-04-27 16:50:27

3beb6e7c46a615a
Member
Registered: 2021-03-27
Posts: 165

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

Well, those three commands would've fixed things… you could've just copied those smile

Offline

#8 2023-04-28 10:37:19

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,142

Re: [Solved] how to clean branch in git fork without deleting&recreating ?

After I deleted the branch with the changes, I checked origin/main and found it was not a 1:1 copy of upstream/main .
There were several merge requests in it by me that needed to go.
( the documentation I got the git merge commands from listed those in the summary , but NOT in the detailed version. I won't be using that doc anymore) .

I removed the local copy, started fresh and executed these commands (lines with # are comments I have added now) :

git clone https://gitlab.freedesktop.org/Lone_Wolf/mesa.git
cd mesa/
git remote add upstream https://gitlab.freedesktop.org/mesa/mesa.git
git checkout main
git fetch upstream
git pull upstream main
# now the local copy has the latest version of upstream, but it still has remnants of the merges
git reset --hard upstream/main
# local copy is now fine
git push origin main
# failed because remote copy still has the incorrect stuff
git push origin main --force
# local & remote origin/main are the same and finally a 1:1 copy of upstream main
git checkout main
git branch -b fix-microsoft-clc
# wrong command
git checkout -b fix-microsoft-clc
# the correct one to create a new branch
git log
# verify no new commits have been added
git checkout fix-microsoft-clc 
# make sure i'm at the right branch
patch --forward --strip=1 --input=/home/panoramix/Temp/0001-compiler-clc-Fix-embedded-clang-headers-microsoft-cl.patch 
git commit
# fails, but helps to verify which files have been changed
git add src/compiler/clc/meson.build 
git commit
patch --forward --strip=1 --input=/home/panoramix/Temp/0002-clc-Add-clangASTMatchers-to-fix-static-llvm-build-of.patch 
git add meson.build 
git commit
git log
patch --forward --strip=1 --input=/home/panoramix/Temp/0003-clc-Add-clang-frontendhlsl-module-to-fix-build-of-mi.patch 
git add meson.build 
git commit
git log
git checkout fix-microsoft-clc 
git push
# failed because the new branch had no remote upstream
git push --set-upstream origin fix-microsoft-clc
# remote branch now should have the 3 commits and nothing else
git rev-list --left-right --count main...fix-microsoft-clc
# verify it indeed has 3 commits

I used the gitlab Web UI to create a new MR which has been merged into mesa main a few hours ago.

A few final comments :
- git rev-list --left-right --count command was an eye opener, I didn't even suspect it could do something like that.

- I've been reluctant to use git reset, but have to study it more as it can be very useful .

- Part of the reason there were 11 commits listed instead of 3 was I had changed commit messages after the commits were pushed.
I assumed that those commands changed existing commits, but that is clearly wrong. They do create a new commit that somehow overrides the old one without reverting it .
No idea how that works, will have to figure it out before doing that again .

Lunaryorn & Wormzy : thank you, your posts helped a lot to clear my mind .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

Board footer

Powered by FluxBB