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
git checkout <current>
git branch <new-name>
# Or as a one liner
git checkout -b <new-name> <current>
(optional) Rebase the PR, from the root folder of your repository:
git fetch origin
git rebase origin/master
# Look for first "new" commit
git log
git reset --soft <commit-hash>
git reset .
git add -p
(optional alternative) Rebase/squash the PR to less commits that you have to pick from
git rebase -i HEAD~10
Steps
git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit)
git reset # unstage the changes from the cherry-picked commit
git add -p # make all your choices (add the changes you do want)
Cancel cherry pick with git cherry-pick --abort
Use git add -p to commit only parts of a file
Info for patch commands:
y - stage this hunk - this command adds the current hunk to staging meaning it is ready.
n - do not stage this hunk - this command won’t add the current hunk to staging.
q - quit; do not stage this hunk or any of the remaining ones - this command quits out of the staging process. Any hunks before this one that has been added to staging will still be staged but the current hunk and all hunks after will be ignored.
a - stage this hunk and all later hunks in the file - this command works similar to the `git add .` call. It will stage all changes made from this hunk on.
d - do not stage this hunk or any of the later hunks in the file - this command will not stage this hunk or any hunks in the same file.
e - manually edit the current hunk- this command opens vim and allow you to edit the hunk of code in your terminal.
? - print help - this opens up the menu above.
s - split this hunk - this option is only available if the current hunk of code has an unchanged line of code between edits. This will split the hunk into two separate hunks allowing you to stage them individually.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Stackoverflow answer: https://stackoverflow.com/a/1526093
root
folder of your repository:Steps
Use
git add -p
to commit only parts of a fileInfo for patch commands:
Finally
Beta Was this translation helpful? Give feedback.
All reactions