100% found this document useful (1 vote)
141 views

Local Version Control System

A version control system records changes to files over time, allowing users to recall specific versions. Git is a distributed version control system where each client fully mirrors the repository and acts as a backup. Key features of Git include speed, simple design, strong support for non-linear development, and ability to handle large projects efficiently.

Uploaded by

Ranjith Kasu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
141 views

Local Version Control System

A version control system records changes to files over time, allowing users to recall specific versions. Git is a distributed version control system where each client fully mirrors the repository and acts as a backup. Key features of Git include speed, simple design, strong support for non-linear development, and ability to handle large projects efficiently.

Uploaded by

Ranjith Kasu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Version Control System

System that records changes to a file or set of files over time so that you can recall
specific versions later.
When there was no version control system, Many peoples version-control method
of choice is to copy files into another directory

Local Version Control System


Centralized Version Control System
Helps to collaborate with developers on other systems.
Has a single server that contains all the versioned files, and a
number of clients that check out files from that central place.
Distributed Version Control System
Clients dont just check out the latest snapshot of the files,
they fully mirror the repository.
Every clone is a full backup of all the data.
If any server dies, and these systems were collaborating via it,
any of the client repositories can be copied back up to the
server to restore it.
History
In 2002, the Linux kernel project began using a proprietary
DVCS called BitKeeper.
In 2005, the relationship between the community that
developed the Linux kernel and the commercial company that
developed BitKeeper broke down, and the tools free-of-
charge status was revoked.
So, there came a need to develop their own tool based on
some of the lessons they learned while using BitKeeper.
Different Distributed VCS
Bazaar Written in Python
BitKeeper - Was used in Linux kernel development.
Git Written in a collection of Perl, C, and various shell
scripts.
Mercurial written in Python as an Open Source replacement
to BitKeeper.
Monotone
Git
Things kept in minds when the development took place :-
Speed
Simple design
Strong support for non-linear development (thousands of parallel
branches)
Fully distributed
Able to handle large projects like the Linux kernel efficiently (speed and
data size)
Git is a distributed version control system.
Source code management system.
Helps software developers to work together and maintain a
complete history of their work.
Maintains a history of every version.
Does not allow overwriting each others changes.
Git vs SVN
GIT is distributed, SVN is not.
GIT like SVN do have centralized repository or server.
GIT stores content as metadata, SVN stores just files.
.git folder is the cloned repository in your machine, it has everything that
the central repository has like tags, branches, version histories etc.
GIT branches are not the same as SVN branches.
Branches in SVN are nothing but just another folder in the repository. In
Git, you can quickly switch between branches from the same working
directory. It helps finding un-merged branches and also help merging files
fairly easily & quickly.
GIT does not have a global revision no. like SVN do.
SVNs revision no. is a snapshot of source code at any given time.
GITs content integrity is better than SVNs
GIT contents are cryptographically hashed using SHA-1 hash algorithm.
This will ensure the robustness of code contents by making it less prone to
repository corruption due to disk failures, network issues etc.
Storing data as changes to a base version of each file.

Storing data as snapshots of the project over time.


Git Basics
Setup :-

Installation :-
sudo apt-get install git-core

Version Check :-
git --version
Customize Git Environment :-

Git config path : /etc/gitconfig file: Contains values for every user on
the system and all their repositories.

Setting identity
git config --global user.name Demo"
git config --global user.email [email protected]

Setting default editor & merge tool


git config --global core.editor vim
git config --global merge.tool vimdiff

Listing Git settings


git config list
Initialize a repo
Initialize a repo
git init
Cloning a repo
git clone [email protected]:project.git
Ignoring files
cat .gitignore *.[oa] *~
Basic Commands :-
git status : It will list out files that are untracked (only in your
working directory), modified (tracked but not yet updated in
your index), and staged (added to your index and ready for
committing).
git add : Adds files changes in your working directory to your
index.
git commit : Takes all of the changes written in the index,
creates a new commit object pointing to it and sets the branch
to point to that new commit.
git push : The Push operation stores data permanently to the Git
repository.
git log : Shows a listing of commits on a branch including the
corresponding details.
git mv : Renames the file.
git rm : Removes files from your index and your working
directory so they will not be tracked.
Undoing Changes :-
One of the common undo takes place when you commit too early and
possibly forget to add some files, or you mess up your commit message. If
you want to try that commit again :-
git commit amend

Unstaging a file :-
git reset HEAD <file name>

Unmodifying a modified file :-


git checkout -- CONTRIBUTING.md

Git Remotes :-
git remote : show short names of remotes
git remote add : add a remote repo
git remote show [remote-name] : inspecting a remote
git push [remote-name] [branch-name] : pushing the changes in a branch
to a remote
The Three States
Review Changes
View commit details :-
git show <commit ID> : Shows the commit details.
git diff : Shows '+' sign before lines, which are newly added
and '' for deleted lines.
Branch Management
git branch : Lists existing branches, including remote branches
if -a is provided. Creates a new branch if a branch name is
provided.
git branch v : Shows last commit on each branch.
git branch merged : To see which branches are already
merged into the branch youre on.
git branch --no-merged : To see all the branches that contain
work you havent yet merged in.
Branches in a Nutshell

A commit and its tree


Commits and their parents

git branch [new_branch] : Creates a new branch


git branch : Lists the available branches. Git shows an asterisk mark
before currently checked out branch.
git checkout [new_branch] : Switches to the branch named new_branch
Git Merge
Suppose youve decided that work is complete and ready to be merged
into your master branch. In order to do that, all you have to do is check
out the branch you wish to merge into and then run the git
merge command :-

git checkout [branch-1]


git merge[branch-2]

Two Types of Merge :-


Fast forward merge
Three way merge
Fast forward Merge

Adding changes in a new branch : The New Branch has moved forward with your work
Three way merge :-

Before Merge

After Merge
Merge Conflicts :-
Occasionally, merge process doesnt go smoothly. If you changed the same part of the
same file differently in the two branches youre merging together, Git wont be able to
merge them cleanly and youll get a merge conflict.

<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
=======
<div id="footer"> please contact us at [email protected]
</div> >>>>>>>
iss53:index.html

Now manually select which part to keep.


git add <file>
git commit , again

Remote Branches :-
Remote-tracking branches are references to the state of remote
branches. Theyre local references that you cant move; theyre moved
automatically for you whenever you do any network communication.
Rebasing
It works by going to the common ancestor of the two branches (the one
youre on and the one youre rebasing onto), getting the diff introduced by
each commit of the branch youre on, saving those diffs to temporary files,
resetting the current branch to the same commit as the branch you are
rebasing onto, and finally applying each change in turn. The primary
reason for rebasing is to maintain a linear project history.

Merging
Rebasing
Stash & Clean
Stash operation takes your modified tracked files, stages changes, and saves them on a stack of
unfinished changes that you can reapply at any time.

git stash

Now you can safely switch the branch and work elsewhere.
We can view a list of stashed changes by :-

git stash list

To remove the changes from the stack and place them in the
current working directory :-

git stash pop

To apply any one of the change from the stack use :-

git apply

To remove untracked directories and files :-

git clean [-d] : Remove untracked directories & files.


Revert Operation
git checkout <file name> : Used to revert the changes in a file,
obtain accidentally deleted files.
git checkout HEAD -- <file name> : Reverts accidentally staged
file, removes the file from the staged area.
git reset : Used to reset the changes, resets the HEAD pointer
which was previously pointing to the latest commit.
Soft Reset : Resets the HEAD pointer only without
destroying anything.
git reset --soft
Mixed Reset : Reverts those changes from the staging
area that have not been committed yet.
git reset --mixed
Hard Reset : Clears the staging area; it will reset the
HEAD pointer to the latest commit of the specific
commit ID and delete the local file changes too.
git reset --hard
Undoing Merges :-

git reset HEAD~


git revert m 1 HEAD :-
Commit Ranges
git diff topic master <1>
git diff topic..master <2>
git diff topic...master <3>

1. Changes between the tips of the topic and the master


branches.
2. Same as above.
3. Changes that occurred on the master branch since when
the topic branch was started off it.
Other Useful Git Features
git blame : If you track down a bug in your code and want to know when it
was introduced and why, It shows you what commit was the last to modify
each line of any file. So, if you see that a method in your code is buggy,
you can annotate the file with git blame to see when each line of the
method was last edited and by whom.
git bisect : The bisect command does a binary search through your commit
history to help you identify as quickly as possible which commit
introduced an issue.
git grep : Look for specified patterns in the tracked files in the work tree
git bundle : The bundle command will package up everything that would
normally be pushed over the wire with a git push command into a binary
file that you can email to someone or put on a flash drive, then unbundle
into another repository.
Summary
git status : It will list out files that are untracked (only in your working
directory), modified (tracked but not yet updated in your index), and staged
(added to your index and ready for committing).
git add : Adds files changes in your working directory to your index.
git commit : Takes all of the changes written in the index, creates a new
commit object pointing to it and sets the branch to point to that new
commit.
git log : Shows a listing of commits on a branch including the corresponding
details.
git mv : Renames the file.
git rm : Removes files from your index and your working directory so they
will not be tracked.
git amend : Convenient way to fix up the most recent commit. Lets you edit
your last commit
git checkout : Checks out a different branch switches branches by updating
the index, working tree, and HEAD to reflect the chosen branch.
git fetch : Fetches all the objects from the remote repository that are not
present in the local one.
git reset : Resets your index and working directory to the state of your
last commit.
git remote : Shows all the remote versions of your repository.
git pull : Fetches the files from the remote repository and merges it with
your local one. This command is equal to the git fetch and the git merge
sequence.
git branch : Lists existing branches, including remote branches if -a is
provided. Creates a new branch if a branch name is provided.
git merge : Merges one or more branches into your current branch and
automatically creates a new commit if there are no conflicts.
git branch d <branch name> : Deletes a branch locally.
git push origin - - delete <branch name> : Deletes a branch remotely
git stash : Temporarily saves changes that you dont want to commit
immediately. You can apply the changes later.
Thanks!!

You might also like