0

I want to generate a PR branch by removing my personal commits

is there ANY way to mark a list of commits to drop

I thought about :

  1. ALWAYS start personal commits with --p: or anything unique
  2. tag personal commits: but this would pollute my tag space: too many tags,
    also, you can't have 2 tags with the same name

    features I want: hidden tags, tags with same name

I could but idk where to feature request to git, to add a way to mark commits.

is there a better way to mark commits ? or generate a PR branch without my personal commits ?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Mr. Doge
  • 796
  • 5
  • 11

1 Answers1

0

so, I've decided to always start personal commits with --p: and made some git aliases:

but I can't predict the future: which changes won't be wanted?
I found a way to mark them AFTER.

MARKING AFTER

If you have unwanted changes that span many commits, or are inside useful commits

  1. remove your personal changes
  2. commit
  3. git revertP

revertP

reverts the last commit and starts the revert message with --p:

revertP = "!HEADID=$(git rev-parse HEAD) && git revert --no-commit HEAD && git commit -m \"--p: revert\" -m \"This reverts commit $HEADID.\" #"

the actual message is:

--p: revert

This reverts commit $HEADID.

if you want to mark a past commit

  1. git revertID <commit>

revertID

self-explanatory (you really should understand the commands before running them)

revertID = "!git revert --no-edit $1 && git revertP #"

examples: git revertID 0d299bd2, git revertID "HEAD^5"


DROPPING

drop

drop all commits starting with --p:: BEWARE, this works on your CURRENT branch

drop = "!GIT_SEQUENCE_EDITOR=\"sed -i '/^pick .\\{7\\} --p:/  s/^pick/drop/'\" git rebase -i --root #"

(I guess rebasing from root is inefficient but faster than specifying the starting point)

generate

takes the 1st command line argument (name of the PR branch)

generate = "!CURRENT=$(git current) && git checkout -b $1 && git drop #"

example:
git generate pr1 will checkout to new branch pr1 and git drop

usually you'd use git generate and not git drop


here's what to put in .gitconfig, for me global config is at: C:\Users\<user>\.gitconfig

[alias]
    drop = "!GIT_SEQUENCE_EDITOR=\"sed -i '/^pick .\\{7\\} --p:/  s/^pick/drop/'\" git rebase -i --root #"
    generate = "!CURRENT=$(git current) && git checkout -b $1 && git drop #"
    revertP = "!HEADID=$(git rev-parse HEAD) && git revert --no-commit HEAD && git commit -m \"--p: revert\" -m \"This reverts commit $HEADID.\" #"
    revertID = "!git revert --no-edit $1 && git revertP #"

thanks to Git alias with positional parameters

Mr. Doge
  • 796
  • 5
  • 11