git reset HEAD~1 --soft
git checkout -- (file name)
Relevant git documentation page
git commit --amend -m "New commit message"
OR with the use of an alias in my .gitconig: git ca "New commit message"
Relevant git documentation page
git reset --hard (commit id)
Relevant git documentation page
git revert (commit id)
to revert the last n commits,
git revert HEAD~n..master
Relevant documentation Atlassian doc
git reset HEAD (file name)
OR with the use of an alias in my .gitconig: git unstage (file name)
Relevant git documentation page
Move a file without git thinking you've removed it and then created a new file that's unrelated to the deleted one
git mv <options>… <args>…
Relevant git documentation page
E.g. which commit removed this line? https://stackoverflow.com/questions/12591247/how-to-find-commit-when-line-was-deleted-removed
git log -c -S'missingtext' /path/to/file
From https://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history :
For this you can use -S and -G, which are subtly different...
The -S option essentially counts the number of times your search matches in a file before and after a commit. The commit is shown in the log if the before and after counts are different. This will not, for example, show commits where a line matching your search was moved.
With the -G option, the commit is shown in the log if your search matches any line that was added, removed, or changed.
For example,
diff --git a/test b/test index dddc242..60a8ba6 100644 --- a/test +++ b/test @@ -1 +1 @@ -hello hello +hello goodbye hello
Because the number of times "hello" appears in the file is the same before and after this commit, it will not match using -Shello. However, since there was a change to a line matching hello, the commit will be shown using -Ghello.
- https://stackoverflow.com/questions/6217156/break-a-previous-commit-into-multiple-commits
- https://stackoverflow.com/questions/26488422/revert-to-last-stable-commit-without-losing-newer-commits
- https://stackoverflow.com/questions/6591213/how-do-i-rename-a-local-git-branch
- https://stackoverflow.com/questions/1394797/move-existing-uncommited-work-to-a-new-branch-in-git
- https://stackoverflow.com/questions/3899627/create-git-branch-with-current-changes