You are on page 1of 21

1

Government Engineering College, Naragund


Department of Technical Education, Government of Karnataka

Version Control
Version control is a system that records changes to a file or set of files over time so that
you can recall specific versions later.
Types of version control systems
Types of version or revision control systems are centralized and distributed. Centralized
version control systems store all the files in a central repository, while distributed version control
systems store files across multiple repositories. Other less common types include lock-based
and optimistic.
o Distributed
A distributed version control system (DVCS) allows users to access a repository from multiple
locations. DVCSs are often used by developers who need to work on projects from multiple
computers or who need to collaborate with other developers remotely.
o Centralized
A centralized version control system (CVCS) is a type of VCS where all users are working with
the same central repository. This central repository can be located on a server or on a
developer's local machine. Centralized version control systems are typically used in software
development projects where a team of developers needs to share code and track changes.
Lock-based
A lock-based version control system uses file locking to manage concurrent access
to files and resources. File locking prevents two or more users from making conflicting
changes to the same file or resource.
Optimistic
In an optimistic version control system,
every user has their own private workspace.
When they want to share their changes with the
rest of the team, they submit a request to the
server. The server then looks at all the changes
and determines which ones can be safely merged

together.

by: Prasannakumar Manuvacharya 1


2
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Centralized Version Control System Distributed Version Control


System

VCS Software’s
o Git — Git is a widely popular, distributed control system for developers. Git source
control is open-source and therefor free to use. It offers easy branching and is great for
small projects but has file and repo size limits.
o SVN — SVN (short for Subversion) is another free, open-source version control system
developed by Apache. It is a centralized version control system. It offers good concurrent
development processes, but its branch and merge functions are not strong.
o TFS — Microsoft TFS (Team Foundation Server), now rebranded as Azure DevOps Server,
is a tool for version control, issue tracking & reporting, and application lifecycle
management.

What is Git?
Git is an open-source distributed version control system. It is designed to handle minor to
major projects with high speed and efficiency. It is developed to co-ordinate the work among
the developers. The version control allows us to track and work together with our team
members at the same workspace.

Features of Git
Some of features of Git are as follows:

by: Prasannakumar Manuvacharya 2


3
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

o Open Source
Git is an open-source tool. It is released under the GPL (General Public License) license.
o Scalable
Git is scalable, which means when the number of users increases, the Git can easily
handle such situations.
o Distributed
One of Git's great features is that it is distributed. Distributed means that instead of
switching the project to another machine, we can create a clone of the entire repository.
Also, instead of just having one central repository that you send changes to, every user
has their own repository that contains the entire commit history of the project. We do not
need to connect to the remote repository; the change is just stored on our local
repository. If necessary, we can push these changes to a remote repository.

o Security
Git is secure. It uses the SHA1 (Secure Hash Function) to name and identify objects
within its repository. Files and commits are checked and retrieved by its checksum at the
time of checkout. It stores its history in such a way that the ID of particular commits
depends upon the complete development history leading up to that commit. Once it is
published, one cannot make changes to its old version.
o Speed
Git is very fast, so it can complete all the tasks in a while. Most of the git operations are
done on the local repository, so it provides a huge speed. Also, a centralized version
control system continually communicates with a server.

by: Prasannakumar Manuvacharya 3


4
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Experiment-1
Initialize a new git repository, create a branch name as featurebranch (format should be
USN_<branch_name>) and create a new file name as addition.c. Add it in staging area commit
the changes with appropriate message and log the changes.

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch #note: use your USN
git checkout 2NR22CS001_featurebranch

by: Prasannakumar Manuvacharya 4


5
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Step-4: Create a file name as <file_name>


If Windows machine: vim addition.c
or
if Linux Machine: touch addition.c and vi addition.c

Add below lines in the addition.c file (Optional) and save it


#include <stdio.h>
int main() {

int number1, number2, sum;

printf(Enter two integers: );


scanf(%d %d, &number1, &number2);

// calculate the sum


sum = number1 + number2;

printf(%d + %d = %d, number1, number2, sum);


return 0;
}
Step-5: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add addition.c
git commit –m “added new file addition.c”

Step-6: Log the changes


git branch –a #View all branches in the repository
git log

Output:

by: Prasannakumar Manuvacharya 5


6
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Experiment- 2
Initialize a new git repository, create a git branches name as featurebranch1,
featurebranch2 (format should be USN_<branch_name>) and add files to the each branch and
merge branches to master.

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.

by: Prasannakumar Manuvacharya 6


7
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

git config --global user.name 2NR22CS001 #note: use your USN


git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch1 #note: use your USN
git branch 2NR22CS001_featurebranch2 #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch1

If Windows machine: vim file1.txt


or
if Linux Machine: touch file1.txt and vi file1.txt

Step-5: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file1.txt
git commit –m “added new file file1.txt”

Step-6: Checkout the branch2 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch2

If Windows machine: vim file2.txt


or
if Linux Machine: touch file2.txt and vi file2.txt

Step-7: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file2.txt
git commit –m “added new file file2.txt”

Step-8: Merge the branches


git merge 2NR22CS001_featurebranch1
git merge 2NR22CS001_featurebranch2

Step-9: Log the changes


git branch –a #View all branches in the repository
git log

Output:

by: Prasannakumar Manuvacharya 7


8
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Experiment- 3
Initialize a new git repository, create a git branches name as featurebranch (format
should be USN_<branch_name>) and add files to the created branch, merge the branch codes
to the master and delete the created branch.

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
by: Prasannakumar Manuvacharya 8
9
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail


If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch

If Windows machine: vim file.txt


or
if Linux Machine: touch file.txt and vi file.txt

Step-5: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file.txt
git commit –m “added new file file.txt”

Step-6: Merge the branch code


git checkout master
git merge 2NR22CS001_featurebranch

Step-7: Delete the branch


git branch -d 2NR22CS001_featurebranch

Step-8: Log the changes


git branch –a #View all branches in the repository
git log

Output:

by: Prasannakumar Manuvacharya 9


10
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Experiment- 4
Initialize a new git repository, create a git branches name as featurebranch1,
featurebranch2 (format should be USN_<branch_name>) and add files to the featurebranch1
branch and modify the files and the stash changes, checkout the featurebranch2 commit the
changes and apply the stash changes.

by: Prasannakumar Manuvacharya 10


11
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch1 #note: use your USN
git branch 2NR22CS001_featurebranch2 #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch1

If Windows machine: vim file1.txt


or
if Linux Machine: touch file1.txt and vi file1.txt

Step-5: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file1.txt
git stash

Step-6: Checkout the branch2 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch2

If Windows machine: vim file2.txt


or
if Linux Machine: touch file2.txt and vi file2.txt

Step-7: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file2.txt
git commit –m “added new file file2.txt”

Step-8: Checkout the branch1 and apply the stash changes


git checkout 2NR22CS001_featurebranch1

by: Prasannakumar Manuvacharya 11


12
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

git stash apply

Step-9: Add it in staging area commit the changes with appropriate message
git add -A or git add . or git add file1.txt
git commit –m “added new file file1.txt”

Step-10: Log the changes


git branch –a #View all branches in the repository
git log

Output:

Experiment- 5
Initialize a new git repository, add below remote repository, create a git branch name as
feature_branch (format should be USN_<branch_name>) and add files to the created branch,

by: Prasannakumar Manuvacharya 12


13
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

merge changes to the master, provide commit message as “merged branch code files to the
master branch ” and add tag version as 1.0.
Remote Repo Url: https://github.com/prasanna-jm/CS-AI-Repo.git

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init
git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail

git remote add origin https://github.com/prasanna-jm/CS-AI-Repo.git


or
git clone https://github.com/prasanna-jm/CS-AI-Repo.git

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch

If Windows machine: vim file.txt


or
if Linux Machine: touch file.txt and vi file.txt

Step-5: Add it in staging area commit the changes with appropriate message and add a tag
git add -A or git add . or git add file.txt
git commit –m “added new file file.txt”
git tag v1.0
git push

Step-6: Add tag as v1.0, Merge the branch code with custom commit message
git checkout master
git merge 2NR22CS001_featurebranch –m “merged branch code files to the master branch”
git push
Step-7: Log the changes
git branch –a #View all branches in the repository
git log

by: Prasannakumar Manuvacharya 13


14
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Output:

Experiment- 6
Write the command to the cherry-pick a range of commits from featurebranch2 to the
featurebranch1 branch.

by: Prasannakumar Manuvacharya 14


15
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_featurebranch1 #note: use your USN
git branch 2NR22CS001_featurebranch2 #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch1

If Windows machine: vim file1.txt


or
if Linux Machine: touch file1.txt and vi file1.txt

git add -A or git add . or git add file.txt


git commit –m “added new file file1.txt”

Step-5: Checkout the branch2 and Create a file name as <file_name>


git checkout 2NR22CS001_featurebranch2

If Windows machine: vim file2.txt


or
if Linux Machine: touch file2.txt and vi file2.txt

git add -A or git add . or git add file2.txt


git commit –m “added new file file2.txt”

Step-6: Get the logs for hash codes, apply the command cherry-pick and paste the hash
by: Prasannakumar Manuvacharya 15
16
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

git log –oneline

git checkout 2NR22CS001_featurebranch1


git cherry-pick d68b94d (Hashcode)

Step-8: Log the changes


git log --oneline

Output:

Experiment- 7
Initialize a new git repository, create a git branch name as feature_branch (format should
be USN_<branch_name>) and add ten files to the created branch, commit the changes for each
created files to the branch, analyse and display the history for the below steps.

by: Prasannakumar Manuvacharya 16


17
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

1) Display the specific commit history


2) Display the commit history between date ranges.

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_feature_branch #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_feature_branch

If Windows machine: vim file1.txt


or
if Linux Machine: touch file1.txt and vi file1.txt

git add -A or git add . or git add file1.txt


git commit –m “added new file file1.txt”

Continue till 10 times


If Windows machine: vim file10.txt
or
if Linux Machine: touch file10.txt and vi file10.txt

git add -A or git add . or git add file10.txt


git commit –m “added new file file10.txt”
Step-5: Get the logs
git log --pretty=format:"%h - %an, %ar : %s"

Step-6:
1) Display the specific commit history.
by: Prasannakumar Manuvacharya 17
18
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

git show 078656c (Commit Id)


2) Display the commit history between date ranges.
git log --since="2024-03-12" --until="2024-03-13"

Output:
Git log

1) Display the specific commit history

2) Display the commit history between date ranges

Experiment- 8
Initialize a new git repository, create a git branch name as feature_branch (format should
be USN_<branch_name>) and add ten files to the created branch, commit the changes for each
created files to the branch, analyse and display the history for the below steps.
1) Display the commit history by the author name.
by: Prasannakumar Manuvacharya 18
19
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

2) Display the top 5 number of commit history in one line.

Step-1: Create a Directory


mkdir 2NR22CS001 #note: use your USN
cd 2NR22CS001

Step-2: Initialize a new git repository, create a directory and initialize the git repo.
git init

Setting up global user name and mail id.


git config --global user.name 2NR22CS001 #note: use your USN
git config --global user.email 2NR22CS001@gmail.com #note: use your USN@gmail
If Windows machine: vim readme.txt
or
if Linux Machine: touch readme.txt and vi readme.txt

Step-3: Create a branch format as USN_<branch_name>).


git branch 2NR22CS001_feature_branch #note: use your USN

Step-4: Checkout the branch1 and Create a file name as <file_name>


git checkout 2NR22CS001_feature_branch

If Windows machine: vim file1.txt


or
if Linux Machine: touch file1.txt and vi file1.txt

git add -A or git add . or git add file1.txt


git commit –m “added new file file1.txt”

Continue till 10 times

If Windows machine: vim file10.txt


or
if Linux Machine: touch file10.txt and vi file10.txt

git add -A or git add . or git add file10.txt


git commit –m “added new file file10.txt”

Step-5: Display the logs


git log --pretty=format:"%h - %an, %ar : %s"

Step-6:
by: Prasannakumar Manuvacharya 19
20
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

1) Display the commit history by the author name.


git log --author=2NR22CS001 --oneline
2) Display the top 5 number of commit history in one line.
git log n 5 –oneline

Output:
Git log

1) Display the commit history by the author name.

2) Display the top 5 number of commit history in one line.

by: Prasannakumar Manuvacharya 20


21
Government Engineering College, Naragund
Department of Technical Education, Government of Karnataka

Thank You 😊

by: Prasannakumar Manuvacharya 21

You might also like