What’s the difference between Git Revert, Checkout and Reset?

These three commands have entirely different purposes. They are not even remotely similar. git revert This command creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn’t modify existing history). git checkout This command checks-out content from the repository and puts it in … Read more

How to checkout in Git by date?

To keep your current changes You can keep your work stashed away, without commiting it, with git stash. You would than use git stash pop to get it back. Or you can (as carleeto said) git commit it to a separate branch. Checkout by date using rev-parse You can checkout a commit by a specific … Read more

Difference between git checkout –track origin/branch and git checkout -b branch origin/branch

The two commands have the same effect (thanks to Robert Siemer’s answer for pointing it out). The practical difference comes when using a local branch named differently: git checkout -b mybranch origin/abranch will create mybranch and track origin/abranch git checkout –track origin/abranch will only create ‘abranch‘, not a branch with a different name. (That is, … Read more

Meaning of Git checkout double dashes

Suppose I have a file named path/to/file.txt in my Git repository, and I want to revert changes on it. git checkout path/to/file.txt Now suppose that the file is named master… git checkout master Whoops! That changed branches instead. The — separates the tree you want to check out from the files you want to check … Read more