Git
Git
COMMANDS---------------------------------------------------------------------------
---
DEFINITION
It is a distributed version control system(DVCS) designed to handle everything form
to small to very large projects with speed and efficiency.It allows multiple
developers to collaborate on project simultaneously.
DVCS
It is a type of version control system where the complete datebase, including its
full version history, is mirrored on every developer’s computer who all are
participating in builiding that project.
BASIC TERMINOLOGY
• Repository(Repo) – a project that contains your project files along with the
modification history.
CONCEPTS
• Hash Value –
It is a chechsum value generated for each commit in order to help us idetify
each commit. This SHA1 value is unique for every commit, even if we do
commit on a file that exist in repository but has been edited and need to be commit
again
• Pointers -
There are two pointers i.e. master and HEAD. Master is the reference of the
end of the default branch created when we initialize a git repository
while HEAD refers to the the parent of next commit and points tothe new
commit as soon as the commit happens.
• Adding a file -
When we add a file the file goes to the staged level and not the repository
directly, so in order to send it to the repo, we need to commit it
• Editing a file -
When we edit a file ,that is already present in the repo, in the local
machine, we need to again add it and commit in order for the changes to be
stored in the repo
• Deleting files -
There are two ways of deleting a file,manually or by using commands.In the
manual method, we directly delete the file from the local machine. By
usinng commands, we first use rm to remove the file from the local machine
and then we need to commit in order for it to be removed from the
repository too.
• Moving and renaming files – can be done by two ways either manualy or by
using mv command. Here moving and renaming refer to same thing, if you want
to rename a file then write $git mv old_name new_name
• Atomic commits – make commits with similar topic /changes related to similar
topics so that it is easier to manage these changes later on
• .gitignore files – these are the files whose changes will not be tracked by
the system/git
• Track empty directories - as git does not track empty directories then in
order to track them we can make a blank file in it
• Merge conflicts – conflicts may arise while merging two different files,you
need to manuaaly correct them.
• Fork - A fork is a copy of a repository that allows you to make your own
changes without impacting the original project.Diff bw fork and clone: A
fork differs from a cloned copy in that it doesn't allow for direct
collaboration with the root using local commands like git push and git pull.
SET UP REPOSITORY
1. open the project directory and type - $git init (initiliazes repository)
---------------------------------------------------------------
COMMANDS---------------------------------------------------------------------------
----------
INSTALLATION COMMAND - $sudo apt install git-all
BASICS
options -
◦ -m – to add a message
◦ -a – commits all changes directly to repository without
firstly adding the files to staged area
◦ -all – same as -a
options -
◦ -n 5 – to limit the number of logs to be displayed
syntax - $git log -n 2
op - commit
8466f62a296712fcef4250d58f81267c4fa87c89 (HEAD -> main)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:56:09 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
commit 1019e6bbbe0697f7b88ed38829857c3e6ae5ef0b
(origin/main, origin/HEAD)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 10:50:55 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
commit 1019e6bbbe0697f7b88ed38829857c3e6ae5ef0b
(origin/main, origin/HEAD)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 10:50:55 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
commit 1019e6bbbe0697f7b88ed38829857c3e6ae5ef0b
(origin/main, origin/HEAD)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 10:50:55 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
commit 1019e6bbbe0697f7b88ed38829857c3e6ae5ef0b
(origin/main, origin/HEAD)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 10:50:55 2024 +0530
hello updated
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
hello updated
hello | 1 +
1 file changed, 1 insertion(+)
commit 13bc9e53e524a9d3b86187554a077080560ffe1a
(origin/hello)
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:20:21 2024 +0530
hello | 0
1 file changed, 0 insertions(+), 0
deletions(-)
commit 6a197026f2e61621dc742dcb4f6d3e21c2b5d4d4
Author: aarzoo <[email protected]>
Date: Tue Mar 5 11:15:39 2024 +0530
0809 added
◦ --graph --decorate - --graph draws a text based graph of
commits on the left side of commit msgs. --decorate adds names of
branches to tags to commit shown
syntax - $git log --graph --decorate
op -* commit
7f4fe0d9a0ead06ecd64ac569b3d9e353988fd67 (HEAD)
| Author: aarzoo <[email protected]>
| Date: Fri Mar 1 17:47:04 2024 +0530
|
| Revert "Revert "Initialize""
|
| This reverts commit
46892176100a1227525899ead7ba83293dac1149.
|
* commit 46892176100a1227525899ead7ba83293dac1149
| Author: aarzoo <[email protected]>
| Date: Fri Mar 1 17:40:14 2024 +0530
|
| Revert "Initialize"
|
| This reverts commit
aa8f989ec1cb1999bde58082a624d724f9ab172c.
|
* commit aa8f989ec1cb1999bde58082a624d724f9ab172c
Author: aarzoo <[email protected]>
Date: Fri Mar 1 12:36:37 2024 +0530
Initialize
• status – used to display the status of the local machine files i.e.
staged,unstaged and untracked file
syntax - $git status
op - On branch main
Your branch is ahead of 'origin/main' by 3 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: hello
• diff – used to show the difference between the file stored in the repo and
the same local file but with some editing present in it.
syntax - $git diff file.txt
op - diff --git a/new1.txt b/new1.txt
index efbc80b..b2f6d72 100644
--- a/new1.txt
+++ b/new1.txt
@@ -1 +1,3 @@
this is my first file
+
+i love working at beryl
option:
◦ --staged – hows the difference berween the newly edited
file that has been edited to the staged index and the original version
of the same file present at the the repo
syntax - $git diff – staged file.txt
op - diff --git a/new 1.txt b/new 1.txt
deleted file mode 100644
index efbc80b..0000000
--- a/new 1.txt
+++ /dev/null
@@ -1 +0,0 @@
-this is my first file
diff --git a/new1.txt b/new1.txt
index efbc80b..b2f6d72 100644
--- a/new1.txt
+++ b/new1.txt
@@ -1 +1,3 @@
this is my first file
+
+i love working at beryl
◦ --color-words – shows only the words that are different instead
of whole line
syntax - $git diff --color-words
op - shows rhe same output just with colors to indicate
changes in the code
◦ --cached – shows difference between staged and last commit
syntax - $git diff --cached
op - diff --git a/hello b/hello
deleted file mode 100644
index bc24472..0000000
--- a/hello
+++ /dev/null
@@ -1 +0,0 @@
-abchdsjijfirfijifknivir
GIT CONFIG
REWRITING
• revert – creates a new commit that undoes all the changes made in the
<commit> and then apply it to the current branch
syntax - $git revert <commit>
example - $git revert 062ac
op - [detached HEAD d0b1086] Revert "4314 to 4315"
10 files changed, 12 insertions(+), 13 deletions(-)
• commit --amend – replaces the last commit with the staged changes and the
last commit (when nothing in staged, used to edit the last commit’s msg)
syntax - $git commit --amend
op - [detached HEAD 0abd327] stash
Date: Mon Mar 4 14:42:29 2024 +0530
10 files changed, 12 insertions(+), 12 deletions(-)
• reset – unstages the stages file without overwritng the changes in the
current directory.
syntax - $git reset <file>
op - Unstaged changes after reset:
M resources.html
options -
◦ --hard – to limit the number of logs to be displayed
syntax - $git reset --hard
op - HEAD is now at 8466f62 hello updated
REMOTE REPOSITORY
GIT BRANCHES
-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
+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
diff --git a/xyz b/xyz
new file mode 100644
index 0000000..011c2e7
--- /dev/null
+++ b/xyz
@@ -0,0 +1,2 @@
+hello im here again
+