General Flashcards
How do I delete the last commit?
git reset –hard HEAD~1 (Discard all changed)
or
git reset –soft HEAD-1 (Keep the Changed Files)
How to change the last commit message?
git commit –amend
Delete a Git Branch Remotely?
git push origin –delete branchname
What is the difference between git pull and git fetch?
git pull, is git fetch followed by git merge. git fetch gets the remote changes, they get kept under refs/remotes//. However it doesn’t affect your local branches, and won’t change your working copy. git pull then merges these changes with the local copy
How do I undo a ‘git add’ before committing?
git reset filename
How to remove all untracked files?
git clean -f -d
How to clone all remote branches?
git branch -a
How to rename a local branch?
git branch -m oldname newname
How to revert to a previous Git Commit?
git reset -hard commitID
You can use reset as above to revert to a previous commit, this assumes you mean go back to where you were before permanently rather than just take a look (for that you want to checkout an old version). The commit ID, should be as shown in the output of “git log”.
How to remove a git submodule?
git submodule deinit submodulename
git rm submodulename
git rm –cached submodulename
rm -rf .git/modules/submodulename
How to over-write local files when doing a git pull?
git fetch –all
git reset –hard origin/master
How to discard all unchecked in changes?
git checkout – .
How to create a new remote branch from the current local branch?
git config –global push.default current
git push -u
How to restore a delete file?
git rev-list -n 1 HEAD – filename
then chekcout that file
git checkout deletingcommitid^ – filename
How to revert a single file to a specific previous commit?
git checkout commitId filename