Git Usage 2 - Cherry-pick, Rebase | Drupal 8

Git Usage 2 - Cherry-pick, Rebase

Submitted by editor on Fri, 09/29/2017 - 11:12
Question

How to use cherry-pick ?
How to use rebase ?

How to change the user name or the email of a commit ?

Cherry pick

Example:

#Checkout the branch you want to insert the commits
git checkout hotfix/Bug-123

#Pick the commits
git cherry-pick 09c075bcd46af4bc94f1d2f8341b0b698506fc9c
#Push the branch
git push origin hotfix/Bug-123

 

Rebase

Merge multiple commits in to one

Example : Merge last 4 commits in to one

git rebase -i HEAD~4
# -> Change pick to squash the commit you want to merge
git push -f origin master

 

Change the user name or the email of a commit

Example 01
git -c user.name="New name" -c user.email=new.email@mail.com commit --amend --reset-author
Example 02
git commit --amend --author "New Author Name <email@address.com>"

Using Interactive Rebase (For multiple commits)

git rebase -i -p <some HEAD before all of your bad commits>
Then mark all of your bad commits as "edit" in the rebase file. If you also want to change your first commit, you have to manually add it as first line in the rebase file (follow the format of the other lines). Then, when git asks you to amend each commit, do
git commit --amend --author "New Author Name <email@address.com>"
edit or just close the editor that opens, and then do
git rebase --continue
to continue the rebase.
You could skip opening the editor altogether here by appending --no-edit so that the command will be:
git commit --amend --author "New Author Name <email@address.com>" --no-edit && \
git rebase --continue

 

Update a branch from master or parent branch

git fetch
git rebase origin/master

 

Tags

Add new comment