You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sudo apt install git-filter-repo
git clone [email protected]:KhronosGroup/SYCL-Doc
cd SYCL-Doc
# Just keep the first parent from each commit to give a squashed view
git filter-repo --refs main --commit-callback 'if len(commit.parents) > 1 : commit.parents = [commit.parents[0]]'# Create a new squashed-main branch upstream.
git push origin main:squashed-main
The text was updated successfully, but these errors were encountered:
You were quicker. Alternative solution created by GPT:
#!/bin/bash
# Set the current branch and main branch names
main_branch="main"
# Find the most recent commit on the current branch with "cherry picked from commit" in the last line of the message
recent_commit=$(git log --format=%H -n 1 --grep="cherry picked from commit")
if [ -z "$recent_commit" ]; then
echo "No recent commit with 'cherry picked from commit' found. Using HEAD as the original commit."
original_commit=$(git rev-parse HEAD)
else
echo "Most recent commit with cherry-pick found: $recent_commit"
# Extract the original commit hash from the cherry-pick message (it's the last word of the commit message)
original_commit=$(git log -1 --format=%B $recent_commit | grep "cherry picked from commit" | awk '{print $NF}' | tr -d ')')
# Check if the original commit hash was extracted
if [ -z "$original_commit" ]; then
echo "Failed to extract the original commit hash."
exit 1
fi
fi
echo "Original commit hash: $original_commit"
# Get all commits after the original commit on the main branch (first-parent only)
commits_to_cherry_pick=$(git log --first-parent --format=%H --reverse $original_commit..$main_branch)
# Check if there are any commits to cherry-pick
if [ -z "$commits_to_cherry_pick" ]; then
echo "No commits to cherry-pick from $main_branch after $original_commit."
exit 0
fi
# Cherry-pick all commits (merge or non-merge) with -m 1 and -x to include the cherry-pick message
echo "Cherry-picking all commits from $main_branch after $original_commit..."
git cherry-pick -m 1 -x $commits_to_cherry_pick
# Check if the cherry-pick succeeded
if [ $? -ne 0 ]; then
echo "Cherry-pick failed. Resolve conflicts, then run 'git cherry-pick --continue' to finish."
exit 1
fi
echo "Successfully cherry-picked all relevant commits from $main_branch."
Advantage of this solution is that it automatically only adds the new commits added since it was called last time. So it can be run in post-commit without having to recreate the branch every time and it refers to the original commit. Disadvantage creating many commits is much slower than with Ronan's solution. But given that this only done once it shouldn't matter.
Whatever solution we pick, regenerating the branch from scratch seems idempotent (generating new hash values every time the script is done would be a nightmare) and is surprisingly done in only a fraction of second.
@VerenaBeckham @etomzak @AByzhynar I put an example of what a simplified history is: https://github.com/KhronosGroup/SYCL-Docs/tree/squashed-main
Interestingly, the link on the PR in the commit title correctly send to the original PR and its commits.
Note that it will be misleading when clicked from the SYCL-SC repository, but we could add a more precise link.
Here is the current recipe using https://github.com/newren/git-filter-repo quite faster than the old
git filter-branch
:The text was updated successfully, but these errors were encountered: