Git and Github Tutorial - Undoing Changes - Part 6

Hi, Today in iThePro we will learn how to use Git and how to use with Github to build software and develop it. In this part we will see how to Undoing Changes.


Undoing working directory (Project) changes:
Once you made a change to a file on the Project and you want get it back to previous from the repository, this command will be you're friend :).
git checkout -- <file-name>
Note : This is undoing changes in the Project from the Repository.

Undoing staging index:
Once we put (add) our changes to the staging index, in order to unstaging files and get them back to the project.
git reset HEAD <file-name>
Retrieving old version: 
Once we want to change the file to previous version, we can do that based on the Commit ID.
git checkout <Commit-ID> -- <file-name>
Amending Commits:
Once we want to change the last commit (Only the last), otherwise to change the message or to add other files to the same last commit !
git commit --amend -m "New Message"
Retrieving a commit:
This will reverse the commit modification, will undo all the changes.
git revert <commit-ID>
 Using git reset to undo many commits:
"git reset" is a really powerful tool, allows us to undo multiple commits, and the same time it's really dangerous.
This command basically allows us to specific where the HEAD pointer should point to, and that's where we going to start recording !
a) Soft reset:
This type of reset change the HEAD point to the specific commit and does not change the staging index or the project.
git reset --soft <commit-ID>
 as a result of this command the change appear in the Repository.

b) Mixed reset (default):
This type of reset change the HEAD point to the specific commit and change the staging index to match the repository, (not the project).
git reset --mixed <commit-ID>
 as a result of this command the change appear in the project.

c) Hard reset:
This type of reset completely change the Repository, staging index and the project.
git reset --hard <commit-ID>
Removing Untracked files:
for fast clean untracked files, git recommended to use "git clean", this command will detect all the untracked files and display them!
git clean -n
 shows all the untracked files.
git clean -f
force git to remove untracked files.


See the Git and Github Tutorials.


Author

OUSSAMA AMRI

Oussama Amri 21 years, security professional from Tunisia. Lover of computer science especially programming and secuirty. Follow me On :

Popular Posts

iThePro.com. Powered by Blogger.