Lab2, Git Commands

"git reset" command 

git reset command is used for undoing different types of changes. Using it we can either discard commits in our private branch or throw away uncommitted changes.
You can pass different parameters to your reset command in order to determine the command's scope.
git reset command has 3 different modes:
  • --soft 
The staged snapshot and working directory aren't changed.
  • --mixed (default)
The staged snapshot is updated to match your commit, the working directory isn't affected.
  • --hard 
The staged snapshot and working directory are both affected. The most frequently used but at the same time the most dangerous option. It completely erases things you no longer want to have.

Removing your last commit example

For example, we committed some changes to our file, but made a mistake and want to revert those changes. One of the ways to do that is to use"reset".
git reset HEAD~1 command will throw away the latest commit undoing all changes that you made in it.


Resetting changes in a specific file 

It's also possible to specify the file which changes you want to reset.

"git checkout" command 

git checkout command can switch you between branches or restore working tree files.

Checkout an existing branch

For example, we want to checkout already existing exampleBranch. 
In order to do that type:
git checkout exampleBranch 
In case you haven't yet created a branch you can enter git checkout -b exampleBranch. This command will create a new exampleBranch and switch to it right away.

Undo changes in the working directory

git checkout command can be used in order to undo changes in your working directory 
For example, we want to revert the local changes in our fs.close.spec.js file. To do that you can simply run git checkout -- fs.close.spec.js command.


Comments

Popular posts from this blog

fs.rmdir() vs fs.rmdirSync() in Node.js

Final Summary Blog Post

Discovering Open Source Projects