Useful Git Commands

I’ve recently started using the git file versioning system and have to say it’s extremely useful and effective, and comes highly recommended.  These are some useful commands that I’ve started to need to use that aren’t always covered in the basic tutorials / chapters in books…

Revert changes to a local file (be careful this will lose all changes made!)

git checkout -- file.txt

Reverting a git pull

git reflog #to get the id of the head before the last pull
git reset --hard [id]

Showing the files changed, and the changes in the last commit

git log --name-status -1
git log -p -1

Show tracking branch information

git remote show origin

Revert a merge

git revert -m 1 

Show files changed in a commit

git show --stat 

Leave a Reply

Your email address will not be published. Required fields are marked *