Lecture 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

LECTURE 6

Shell and scripting Programming with Unix


By
Dr.Ashraf Hendam
OUTLINE
• Introduction
• Version Control System
• What Is Version Control system?
• Version Control system Act, Types and Example
• Benefits of Version Control
• Famous Version Control Systems
• Git and GitHub
• How does Git work?
• Git Concept
• Repository Content, Branching and Commit
• Installing Git and Configure git environment
• Creating a project
• Stage
• commit
• Stage and commit example
Introduction
• How many times have you written a document an essay perhaps
where you think you have got to your final version and called it
EssayFinal.
• Read through it again and spot some errors, so you rename it
EssayFinal2.
• Perhaps it’s a dissertation and you give it to your supervisor who
has some comments so you end up with EssayFinalRevised.
• Perhaps you now realise it’s too long so delete some stuff and
create EssayFinalRevisedCut.
• Then you read it again and realize that you really need to add
something back from an earlier version as it no longer makes sense
Wait.
• Did you keep that earlier version?
Version Control System
Multinational company may face several problems
Version Control System
Challenges
1. Collaboration among employees
many people located at different places, there may be a
need to communicate for a particular reason, or a set of
people are working on the same project but from
other regions.
2. Storing several versions of files being made
project is completed into several versions; in that
situation, keeping all such commits in a single place is
a considerable challenge.
Version Control System
3. Data backing up.
If the system or disk of the user breaks down and there is no
backup, then all the efforts go in vain.
4. Restoring Previous Versions
Sometimes, there is a need to go back to the earlier versions
to find the bug's root cause.
5. Figure Out What Happened
It is critical to know what changes were made to the previous
versions of the source code or where exactly the changes
have been made in a file.
What Is Version Control system?
• known as source control or revision control is a
system that tracks the progress of code across the
software development lifecycle and its multiple
iterations – which maintains a record of every
change complete with authorship, timestamp, and
other details – and also aids in managing change.
• The system refers to the category of software tools
that make it possible for the software team to look
after the source code changes whenever needed. The
system records all the made changes to a file so a
specific version may be rolled if required in the future.
Version Control system Act
Version control systems Types
The two most popular types of version or revision control systems
are centralized and distributed.
1. Centralized version control systems
Stores all the files in a central repository and all users are working
with the same central repository. The repository can be located on
a server or on a developer's local machine. The major drawback of
CVCS is its single point of failure
2. Distributed version control systems
Clients fully mirror the repository. If the sever goes down, then the
repository from any client can be copied back to the server to restore
it. You can commit changes, create branches, view logs, and perform
other operations when you are offline. You require network
connection only to publish your changes and take the latest changes.
Version control systems Types
3. 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.
4. 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.
Version control systems Example
There are 3 workstations or three different developers at three other
locations, and there's one repository acting as a server. The work stations
are using that repository either for the process of committing or updating
the tasks.
Benefits of Version Control
1. Streamline merging and branching
Team members should work simultaneously. Designating a branch
in VCS tools, developers can keep several streams of work separate
while still having the option to merge them back together to ensure
that their changes don’t conflict.
2. Examine and experiment with code
The development of any source code is continuous in the modern
world. There are always more features to be added, more people to
target, and more applications to create. When working on a
software project, teams frequently have various main project clones
to build new features, test them, and ensure they work before
uploading this new feature to the main project.
Benefits of Version Control
3. Keep track of every change made to the code
The team tasked consistently generates new source codes and
makes changes to the already existing code. These modifications are
kept on file for future use and can be consulted if necessary to
determine the true source of a given issue.
4. Access every file’s entire long-term modification history
Every modification made over time by numerous people such as file
addition, deletion, and content modifications are all examples of
changes. You should also include the author, the date, and written
comments outlining the rationale behind each change in this history.
Benefits of Version Control
5. Create regular, automated backups
Making a backup of the repository’s most recent version is probably
the most significant advantage. We can protect the data from loss in
the event of a server failure by having numerous backups on various
workstations.
6. Stay compliant with regulations
The accurate change tracking provided by version control is a great
way to get your records, files, datasets, and/or documents ready for
compliance. Regulatory compliance must permeate every aspect of
a project. It requires identifying team members who had access to
the database and accepting accountability for any changes.
Famous Version Control Systems
Git and GitHub
Git and GitHub are not the same thing.
• Git
Is an open-source, version control tool created in 2005 by
developers working on the Linux operating system.
• GitHub
Is a company founded in 2008 that makes tools which integrates
with git. You do not need GitHub to use git, but you cannot use
GitHub without using git.
• There are many other alternatives to GitHub, such as GitLab,
BitBucket, and “host-your-own” solutions such as gogs and gittea.
• You do not need to use a remote to use git, but it will make
sharing your code with others easier.
How does Git work?
• Git stores your files and their development history in a local
repository.
• Whenever you save changes you have made, Git creates a
commit.
• A commit is a snapshot of current files.
• These commits are linked with each other, forming a
development history graph.
• It allows us to revert back to the previous commit, compare
changes, and view the progress of the development project.
• The commits are identified by a unique hash which is used to
compare and revert the changes made.
Repository Content
• Repository is working on all files that are not
generated by a tool:
 source files (.c .cpp .java .y .l .tex . . . )
 build scripts / project files (Makefile configure.in
 Makefile.am CMakefile.txt wscript .sln)
 documentation files (.txt README . . . )
 resource files (images, audio, . . . )
• Files generated will not be a part from the repository
such as files with extensions .o .a .so .dll .class .jar
.exe .dvi .ps .pdf
Branching
• The branches are copies of the source code that works parallel to
the main version.
• To save the changes made, merge the branch into the main
version.
• Each developer has his/her task, and by using branches, they can
work on the new feature without the interference of other
teammates.
• Once the task is finished, you can merge new features with the
main version (master branch).
Commit
• There are three states of files in Git: modified, staged, and commit.
• When you make changes in a file, the changes are saved in the local
directory.
• They are not part of the Git development history.
• To create a commit, you need to first stage changed files.
• You can add or remove changes in the staging area and then package
these changes as a commit with a message describing the changes.
Installing Git
• In order to use Git, you have to install it on your
computer.
sudo apt-get install git
• To verify the installation the following command on
the command line:
git --version.
This shows you the current version installed on you PC.
Configure git environment
To set your username, type and execute these
commands:

git config --global user.name "Your Full Name"


git config --global user.email [email protected]

Git stores this information in the ~/.gitconfig file.


Creating a project
Create a new folder to include project files
mkdir tmp
cd tmp
mkdir test1
cd test1
Now to initialize your project, simply run
git init
This will tell Git to get ready to start watching your files
for every change that occurs.
Stage
git add <filename>
• Signals to git that the specified file should be
“tracked” for changes
• Places modified file(s) in the “staging area”
• Files not added in this way are essentially ignored by
git
• git add -A signals to git that it should track all existing
files
commit
git commit -m "message"
● Takes a "snapshot" of all files currently on the staging
area and commits it to git's memory
● The "snapshot" is captioned with the given message as
a brief description for the commit
Stage and commit example
Stage and commit example

You might also like