Git basic and essential commands
→ Git is a tracker or version control system which tracks different versions of the same file.
Git is used to see the ultimate truth for a code on which the whole team can rely upon. Git lets us see who changed the code, when it was changed, what was changed and even if the code has a bug, it can be reverted back to the cleaner version of the code. It makes collaboration easy and prevents the code from getting messy.
→ Key terminologies:
Staging area → stage refers to ki jidhar performance hone wala ho. To jo bhi stage pr aayga wo commit yani ki save hone ke liye ready ho jayga. Basically maine file ko track krna shuru kr diya hai.
commited area → Whatever was in the staging area are shifted to commited area where the file actually gets saved.
head → The latest commit is called head. Each commit stores the reference of its previous commit like a linked list.
→ Git commands
git init → It simply tells the folder now youre been initialized. You are going to be tracked in future. It makes the .git/ folder which will track the code.
git add <filename> → It adds the file into the staging area. This code is finally getting started to be tracked.
If “git add .” is used then it will add files in the folder to the staging area.
git status → It simply tells the user that which part of the code is changed in the main file which is not yet sent to the staging area. It just reminds that which part of the code will get commited.
git commit -m “<Message>“ → Whatever is in the staging area will get commited with the message written. This message usually tells that the commit does a particular job. Also, each commit gets an id.
git diff → Between two files, it tells what is the difference between these two files determined by their id.
git log → GIves detailed commit history. git log —oneline gives one line history of commits.
git revert <id> → it adds the code which was removed from that id wala code and removes what was added in the code. It basically was complemet. and is added as a new commit.
git reset —hard <id> → It shifts the head to the id here and thus the refernce to other ids after them gets lost. Thus unaccesible and this thing cant be done back. So better to use revert one.