If the commit has already been pushed and the changes need to be applied to the remote source (aka origin): the origin implies the remote branch of the current local one you are on
git push origin --force-with-lease #this will OVERWRITE the GIT history only if no one else has pushed something before you
git branch -d the_local_branch
git push origin --delete the_remote_branch
Created a local commit not yet pushed to the wrong branch => move N of such commits to a new branch:
git branch WRONG_BRANCH git reset --hard||--soft HEAD~NUMBER_OF_LOCAL_COMMITS MOVE TO THE NEW BRANCH (assuming it already exists)
git checkout NEW_BRANCH
Created a local commit not yet pushed to the wrong branch => undo this last commit to restore the working-tree (changes that git shows you when you modify a file and see with git status
):
git reset --soft HEAD^
-
Add files forgotten before:
git add FILE_TO_ADD_TO_STAGE git commit --amend --no-edit
-
Change the author of a commit:
git commit --amend --author "Name and Surname "
-
Change the commit message:
git commit --amend -m "an updated commit message"
git checkout mybranch
git rebase -i origin/REFERENCE_BRANCH # Usually the reference is the branch from which you branched off
Each commit has a prefix which is pick
-For how many commits you want at the end of the squash process, the same number of pick
prefixed commits you must have.
For each commit replace pick
with s
(or squash
) to keep also the commit message OR f
(or fixup
) instead to discard it and keep only the commit changes.
-save and exit
Stage (git add) and solve each conflict you could have and move forward after each step with git rebase --continue
after staging the changes.
Merge a branch without having the famous commit "merge of branch X into Y" in the git commit history and all commits in ONE unique
git merge --squash
git log --oneline --author EMAIL_ADDRESS --after="yesterday"
git pull --rebase origin REFERENCE_BRANCH # where --rebase[=(false|true|merges|preserve|interactive)]
git rm --cached FILEorFOLDER