Amend
amend
**
Amend author
If you want to change the author details of the commit message, you can do it using flag --amend
git commit --amend --author="Kautilya <kautilya@email.com>"
git commit --amend --author="Kautilya <kautilya.save@product_name.com>"
SO | change commit for one commit
Error if you have an index lock error refer to errors
Change Timestamp
This only works for the last commit in the git history tree.
git commit --amend --date=now
git commit --amend --no-edit --date=now
git commit --amend --no-edit --date "2001-09-11T12:14:00-00:00"
SO change-the-timestamp-of-an-old-commit
Git Commit Date with alias
Going with Environment variable way to trick git into committing the date time on its amend operation
GIT_COMMITTER_DATE=<date> git commit --amend --no-edit --date <date>
rebasing and amending commit date
Or combined both
LC_ALL=C GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
Rebase Timeline
Eg. You have 4 commits in git history, not pushed to server.
You want to either do a cherry pick of 2 commits for one PR and 2 for other config PR.
You don't want to have more than 500 LOC in one PR for a reviewer.
// Go to commits back from head
git rebase -i HEAD~2
depending on ur editor Vim or neoVim or nano to get into ur insert mode
pick 27a387e8 feat(AD): VOD DAI #420
pick 6e866579 test(AD): unit test refactor
# Rebase 2fe73117..6e866579 onto 2fe73117 (2 commands)
edit the pick to edit
Do your magic of adding more files or removing or thinning.
Heck you can also change times on your commits, just make sure you change all the 3 associated commits since its been only 4 years I learnt that git logs have 3 diff commit date/time values.
git add <files>
git commit --amend
git rebase --continue
Empty Commit
Sometimes we want to not commit anything and just need some change set in order to trigger a build on CI or Github Actions.
git commit --allow-empty -m "bump for CI"
git push
Specific commit amend
~ is important
Please note the tilde ~ at the end of the command, because you need to reapply commits on top of the previous commit of cec643cd (i.e. cec643cd~).
git rebase --interactive cec643cd~
Then use i for insert, esc for :, :w for write, :q for quit.
so now you're on cec643cd commit & you can edit few things
git commit --amend
Check author date, commit date from logs.
git log --format=fuller
squash the commits and then you can remove that commit.
Switch to soft when you want to delete the head commit but also keep the untracked files.
remove last commit and put it in unchanged stage changes.
you can use --hard if you don't want those changes in changeset.
git reset --soft HEAD~
Cherry Pick
Cherry picking git commits
git cherry-pick `git_hash`
git cherry-pick 03d6929
Sometimes if the commit is present already with its changes it will present this message.
nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git cherry-pick --skip'