- Git is the most popular version control system in the world.
- A version control system recoeds the changes made to our code over time in a special database called repository .
- Repository means a place or something to store data ( Git usualy stores the code data )
-
We can see the project history that who changes them and when.
-
We can also relative the previous data.
-
Centralized.
-
Distributed.
-
In centralized systems, all team members must connect to the server to get the latest copy of the code.
-
Need to share the code with others.
-
EXAMPLE: subversion and team Foundation Server.
- If server goes offline , no one can access.
-
we will have copy of project code , history in local system.So even the file gos offline , we can synchronise the code between us.
-
EXAMPLE : Git and Mecurial.
- It is free source.
- Open source,
- Super fast.
- Scalable.
- CheapBranching/ Merging.
- Command line --> It is always available and fast.
- Code Editors , IDE --> Ex: VS code.
- Grafical User Interface (GUI tools).
- Source Tree.
- mac OS --> Press command + space and type terminal.
- Windows OS --> Click the search icon and type cmd.
- Ubuntu OS --> click Contril + ALT + t.
git --version --> To see the version of git.
- We should specify the following data while configuring git.
- Name .
- E-mail.
- Default editor.
- Line Ending.
- System Level --> For all users.
- Global Level --> All repositories of the current user.
- Local Level --> The current repository.
- git config --global user.name "User name " --> To set user name.
- git config --global user.email "email" --> To set email id .
- git config --global code.editor "code --wait" --> To set default editor.
- git confug --global -e --> To edit above details.
- git config --global core.autocrlf input --> Use this command for linux / mac.
- git config --global core.autocrlf true --> Use this command for windows.
-
Windows uses end of lines as /c or /n as next lines.
-
Ubunu uses only /n as next line.
- git config --help --> to get help from git .
- git config -h --> Shortcut to get help.
- Step 1 : Create directory.
- step 2 : Initialize git (empty) by git init command . A sub file is ceated within the fle . We cannot see that , we can only see using ls -a command. .git file will be present in the same file which contains copy of the current project files. NOTE : rm -rf .git --> to remove sub git repository (DON'T do this)
- Step 3 : Finish work .
- Step 4 : After completion , we nedd to stage our changes using git add . command. Staging area is an intermediate state allows us to review our work before record it using commit the changes . We can also unstage them and add to another commit .
- Step 5 : After staging , Use git command -m "meaningful message" commanded to commit the changes. commit is like taking snapshots of our work that means recording the work and maintain history.
-
Must use valid commit message to maintain good history of work . It is used to get easy identification of particular portion of the code.
-
Our staging area will remain the last version of our code with last commit. It will not delete the old version once it committed.
-
Each commit consists Unique id, message ,Date/time ,Author and complete snapshot of our code.
-
The unique id is generated by git unique for each commit.
-
The snapshot takes complete project everytime , not updating the old.
-
Each commit compresses the content and it doesn't store duplicate content.So , no data storage is wasted.
- git status --> It is used to see the status ofthe working directory on the staging area.
- git add --> for single file.
- git add --> for multiple files.
- git add . --> for all file ( Be careful while using ) .
- git add *.txt --> files that contains .txt extensions.
- git commit -m "message" --> messages should be meaningful.
- To give a detailed commmit message for good understanding. Use / Type --> git commit and press enter Type your short and detailed descreption in the opened file and close yhe file to stop the process.
- As you reach a state you want to record Then , make a commit.
- Each commit should represent a logically seperate change set.
- Always use past tence in commit message.
- Mostly DO NOT use this method.
- If we are sure on our code (Whenever our code is not require review , skip yhe staging area )
- Use git commit -am "without staging" Here a is fr all and m is for message.
-
Commands to remove files from our local and the repository as well are below:
-
git rm -r filename.
-
git rm -r -f filname --> to force remove the file.
-
git rm -r --cached filename --> not to remove.
- i mv filename1 filename2 --> here moving and rename happens simultaneously.
- Special file --> .giignore --> attach this file in te file where we don't need stageing.
- git status -s --> this will show the short type of work status .
- git diff --staged --> This will display a detailed comparison of old and current versions of last commited files to git.
-
There are lot of differnet tools first configure the setting to make vs code as default DIFF TOOL.
-
git config --global diff.tool vscode
-
git config --global difftool.vscode amd "cde --wait"
- git log --> It will show the history of all commits made with the unique id, author, date and time.
- git log --oneline --> It will display the shortest things in history.
- git log --oneline --reverse --> It will show the history in reverse order.
- git show HEAD -->It is also display the last commit details with detailed descreption.
- git ls-tree HEAD~1
- commits.
- BLobs(Files).
- Trees (Directions).
- Tags.
- git restore --staged filename
- git restore .
- git clean -f
- git restore --source=HEAD~1 filename