Table of Contents

Git

Oh-My-Zsh git command alias reference (kudos to thoughtworks)

Things NOT to do

Amend author of last commit

git commit --amend --author="John Doe <john@doe.org>"

Reset file

git checkout -- path/to/file

Pull

git pull --rebase

# or

git pull --no-ff

Branches

i.stack.imgur.com_qrate.jpg

–soft is discarding last commit,

–mix is discarding last commit and add,

–hard is discarding last commit, add and any changes you made on the codes which is the same with git checkout HEAD

List

git branch -a

Delete local

git branch -d test

Delete remote

git push origin --delete test

Cleanup branches on local which have been deleted on remote

git fetch --prune

How to: Fixup bad commit

git reset --soft HEAD^

# or

git reset --soft HEAD~1

Then reset the unwanted files to leave them out from the commit:

git reset HEAD path/to/unwanted_file

# or

git rm --cached path/to/unwanted_file

Now commit again, you can even re-use the same commit message:

git commit -c ORIG_HEAD

How to: Remove modified files from PR

git checkout origin/master -- src/main/java/HelloWorld.java
git commit -m "Removed a modified file from pull request"
git push origin <pull-request-branch>

https://stackoverflow.com/questions/39459467/remove-a-modified-file-from-pull-request

How to: Rebase active branch onto another branch

First, commit your current changes

git commit
git checkout -b backup

Secondly, switch to the target branch

git checkout master

Thirdly, rebase the source branch onto the target branch

git rebase <parent commit hash BEFORE first feature commit> --onto <feature branch name> --committer-date-is-author-date

fatal: cannot rebase with locally recorded submodule modifications

"fatal: cannot rebase with locally recorded submodule modifications"

Run commands separately:

git fetch
git rebase
git submodule update

OR

git rebase --no-recurse-submodules

OR

Commit your submodule changes before rebasing