Source: https://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git
Note: Any changes not committed will be lost.
git branch newbranch # Create a new branch, saving the desired commits
git reset --hard a1b2c3d4 # or git reset --hard HEAD~3 to move master back by 3 commits
git checkout newbranch # Go to the new branch that still has the desired commits
git checkout existingbranch
git merge master
git checkout master
git reset --hard a1b2c3d4 # or git reset --hard HEAD~3 to move master back by 3 commits
git checkout existingbranch
source: https://www.internalpointers.com/post/squash-commits-into-one-git
Choose the hash of the commit until which the merge will be done. The selected commit itself will not be included into the merge.
git rebase -i 72eae16d4f8af8db6
- in the first popped up editor put pick to the commit that is used to merge into
- put squash to the commits that will be merged into the previous first picked commit, save and close
- in the second popped up editor delete all and put your commit message
- use
git push origin your_branch
(git push origin +your_branch
, + is needed to force update if you need to merge into remote branch as well)
Source: https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely
git branch -d branch_name # delete local branch
git branch -D branch_name # delete local branch force
git push origin --delete branch_name # delete remote branch
git clone old_url . # clone from the old repo
git checkout master # checkout to master
# download all branches
for remote in `git branch -r`; do git branch --track $remote; done
git fetch --all
git pull --all
# add location for the new repo
git remote add origin2 new_url
# push repo to the new location
git push --all origin2
source: https://tecadmin.net/delete-commit-history-in-github/
git checkout --orphan temp_branch
git add -A
git commit -am "the first commit"
git branch -D master
git branch -m master
git push origin +master
git fetch origin
git reset --hard origin/master
source: https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf
git config --global core.autocrlf false # per-user solution
git config --local core.autocrlf false # per-project solution
source: https://stackoverflow.com/questions/4850717/how-to-cancel-a-local-git-commit
git reset --soft commit_id_or_branch # keep the local changes
git restore --staged .. # unstage your changes after soft reset
git reset --hard commit_id_or_branch # delete the local changes