git pull origin master --allow-unrelated-histories
git cherry-pick -x <sha>
git log -S "string to find"
git push origin mybranch --force-with-lease
git commit --amend -m 'xxxxxxx'
git show -s --format=%ci HEAD
git reset HEAD^ --hard
git push --force-with-lease [remote] [branch]
git reset --soft HEAD@{1}
git commit --amend -m "New commit message"
git add file
git commit --amend --no-edit
git rm -r one-of-the-directories
git commit -m "Remove duplicated directory"
git push origin <your-git-branch>
git rm -r --cached myFolder
git branch --no-merged master
git branch -a --no-merged master
git add -p
git checkout -b <branch> <SHA1_OF_COMMIT>
(master)$ git reflog
ab7555f HEAD@{0}: pull origin wrong-branch: Fast-forward
c5bc55a HEAD@{1}: checkout: checkout message goes here
Simply reset your branch back to the desired commit:
$ git reset --hard c5bc55a
(master)$ git reflog
69204cd HEAD@{0}: checkout: moving from my-branch to master
4e3cd85 HEAD@{1}: commit: foo.txt added
69204cd HEAD@{2}: checkout: moving from master to my-branch
(master)$ git checkout -b my-branch-help
Switched to a new branch 'my-branch-help'
(my-branch-help)$ git reset --hard 4e3cd85
HEAD is now at 4e3cd85 foo.txt added
(my-branch-help)$ ls
README.md foo.txt
git log -U -m --simplify-merges --merges -- a.txt
If solution is to accept local/our version, run:
git checkout --ours PATH/FILE
If solution is to accept remote/other-branch version, run:
git checkout --theirs PATH/FILE
# create a new branch from the current state of master
git branch some-new-branch-name
# remove the commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# your commit lives in this branch now :)
Solution 1
# undo the last commit, but leave the changes available
git reset HEAD~ --soft
git stash
# move to the correct branch
git checkout name-of-the-correct-branch
git stash pop
git add . # or add individual files
git commit -m "your message here"
# now your changes are on the correct branch
Solution 2
git checkout name-of-the-correct-branch
# grab the last commit to master
git cherry-pick master
# delete it from master
git checkout master
git reset HEAD~ --hard