+ All Categories
Home > Documents > mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control...

mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control...

Date post: 24-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
25
1 Documentation on GIT DOCUMENTATION ON GIT WITH COMMANDLINE ON WINDOWS -Mounika Reddy.D
Transcript
Page 1: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

1 Documentation on GIT

DOCUMENTATION ON GIT WITH COMMANDLINE

ON WINDOWS

-Mounika Reddy.D

Page 2: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

2 Documentation on GIT

Index---------------------------------------------------------------------------------

1.Git

1.1.Version control system----------------------------------------------------------------4 1.2.Localized or Centralized version control systems ------------------------------4 1.3.Distributed version control systems-----------------------------------------------5 1.4.Git----------------------------------------------------------------------------------------5

2.Tools

2.1.Git command line tools --------------------------------------------------------------6

3.Important terminology used in Git-------------------------------------------6

4.Summary of Git terminology

4.1.Reference-------------------------------------------------------------------------------64.2.File states in the working tree------------------------------------------------------7

><Note1:--------------------------------------------------------------------------------------7 ><Note2:--------------------------------------------------------------------------------------7

5.Git commands >git version-----------------------------------------------------------------------------9 >git config >git init >git clone---------------------------------------------------------------------------------9 >git add----------------------------------------------------------------------------------10 >git commit---------------------------------------------------------------------------- 10 >Synchronization with remote repositories--------------------------------------10 >git status-------------------------------------------------------------------------------11 >git log----------------------------------------------------------------------------------11 >git diff----------------------------------------------------------------------------------12 >git tag-----------------------------------------------------------------------------------13 >git show--------------------------------------------------------------------------------13 >git branch----------------------------------------------------------------------------14 >git rm-----------------------------------------------------------------------------------15 >git merge-------------------------------------------------------------------------------15 >git push--------------------------------------------------------------------------------15

Page 3: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

3 Documentation on GIT

>git fetch----------------------------------------------------------------------------------16 >git pull-----------------------------------------------------------------------------------16 >git remote-------------------------------------------------------------------------------17 >echo--------------------------------------------------------------------------------------17 >touch-------------------------------------------------------------------------------------17 >git revert---------------------------------------------------------------------------------18 >git reset----------------------------------------------------------------------------------18 >git checkout-----------------------------------------------------------------------------19 >git mv------------------------------------------------------------------------------------19 >git clean----------------------------------------------------------------------------------20

Page 4: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

4 Documentation on GIT

1.Git :

1.1. V ersion control syste m:

A version control system (VCS) allows you to track the history of a collection of files. It supports creating different versions of this collection. These versions are stored in a specific place, called a repository.The process of creating different versions (snapshots) in the repository is depicted in the following graphic..

VCS are typically used to track changes in source code for a programming language or other text files, like HTML code or configuration files. But a typical version control system can put any type of file under version control, e.g., you may use a VCS to track the different versions of your company logo.

1.2. Localized and centralized version control systems : A localized version control system keeps local copies of the files.A centralized version control system provides a server software component which stores and manages the different versions of the files and let developer copy (checkout) a certain version onto their individual computer.Both approaches have the drawback that they have only one single point of failure, e.g., in localized version control systems the individual computer and in a centralized version control systems the server machine.

Page 5: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

5 Documentation on GIT

1.3. D istributed version control system :

In a distributed version control system each user has a complete local copy of a repository on his individual computer. The user can copy an existing repository. This copying process is typically called cloning and the resulting repository can be referred to as a clone.Every clone contains the full history of the collection of files and a cloned repository has the same functionality as the original repository.Every repository can exchange versions of the files with other repositories by transporting these changes. This is typically done via a repository running on a server which is, unlike the local machine of a developer, always online. Typically there is a central server for keeping a repository but each cloned repository is a full copy of this repository.

1.4. Git :

Page 6: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

6 Documentation on GIT

Git is currently the most popular implementation of a distributed version control system.Git originates from the Linux kernel development and was founded in 2005 by Linus Torvalds. Nowadays it is used by many popular open source projects, e.g., the Android or the Eclipse developer teams, as well as many commercial organizations.

The core of Git was originally written in the programming language C, but Git has also been re-implemented in other languages, e.g., Java, Ruby and Python.

2. Tools :

2.1.Git command line tools:

The original tooling for Git is based on the command line, i.e., the Git development team provides only tooling for the command line. Most of the following examples are based on the Git command line tooling which offers all capabilities of Git.Other Tools:>Eclipse plugin (EGit)>Git4Idea>KDevelop> NetBeans plugin>Padre>PIDA>TextMate>Vim>Visual Studio...etc.

3.  Important terminology used in Git :

>Local Repository>Remote Repository>Concept of Branches>Cloning>Creating>Deleting>Synchronization with Remote Repositories>Staging>Operations(push,pull,add file,log,version,status,clear,delete,merge,fetch..etc)

4. Summary of Git Terminology:

4.1.Reference:

>Branch:

Page 7: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

7 Documentation on GIT

A branch is a named pointer to a commit. Selecting a branch in Git terminology is called to checkout a branch. If you are working in a certain branch, the creation of a new commit advances this pointer to the newly created commit.You can create a new branch from an existing one and change the code independently from other branches. One of the branches is the default (typically named master). The default branch is the one for which a local branch is automatically created when cloning the repository.

>Commit: When you commit your changes into a repository this creates a new commit object in the Git repository. This commit object uniquely identifies a new revision of the content of the repository.This revision can be retrieved later, for example, if you want to see the source code of an older version. Each commit object contains the author and the committer, thus making it possible to identify who did the change. The author and committer might be different people. The author did the change and the committer applied the change to the Git repository. This is common for contributions to open source projects.

>Repository: A repository contains the history, the different versions over time and all different branches and tags. In Git each copy of the repository is a complete repository. If the repository is not a bare repository, it allows you to checkout revisions into your working tree and to capture changes by creating new commits. Bare repositories are only changed by transporting changes from other repositories.

>Staging: The staging area is the place to store changes in the working tree before the commit. The staging area contains a snapshot of the changes in the working tree (changed or new files) relevant to create the next commit and stores their mode (file type, executable bit).

>Working Tree: The working tree contains the set of working files for the repository. You can modify the content and commit the changes as new commits to the repository.

>Cloning,Creating and Deleting: The process of copying an existing Git repository is called cloning. After cloning a repository the user has the complete repository with its history on his local machine. Of course, Git also supports the creation of new repositories.If you want to delete a Git repository, you can simply delete the folder which contains the repository.

4.2. File states in the working tree:A file in the working tree of a Git repository can have different states. These states are the following: Untracked: The file is not tracked by the Git repository. This means that the file

never staged nor committed. Tracked: Committed and not staged

Page 8: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

8 Documentation on GIT

Staged: Staged to be included in the next commit Dirty / Modified: The file has changed but the change is not staged

Note1: Download and install the latest version of Git by using the link https://git-

scm.com/downloads .This will automatically install Git and keep it up-to-date for you.

Note2:>>First we have to create a folder ,where we have got a stuff..>>Right click on that folder and choose the option "git bash here"

Page 9: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

9 Documentation on GIT

>>The Git bash page appears like this

5.Git Commands:

>git version: Note:To know the version of git Commands Used:

git --version

>git config: Task:Tell Git who you are Note:Configure the author name and email address to be used with your commits.You have to configure at least your user and email address to be able to commit to a Git repository because this information is stored in each commit.Configure your user and email for Git via the following command.Commands Used: git config --global user.name “MounikaReddyDuvoori” git config --global user.email “[email protected]

Page 10: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

10 Documentation on GIT

>git init:Task:To Create a new local RepositoryNote: Create an empty Git repository or reinitialize an existing one.Commands Used: git init

>git clone:Task:Check out a repositoryNote:Creating a working copy of a local repository.Commands Used:

Local : git clone /path/to/repository Remote: git clone username@host:/path/to/repository

>git add,git commit: git add: Task: Add files Note:Add one or more files to staging(index) Commands used: git add <filename> git add * git commit: Task:Commit Note:Commit changes to head (but not yet to the remote repository) Commit any files you've added with git add, and also commit any files you've changed since thenCommands used: git commit -m “commit message”

Page 11: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

11 Documentation on GIT

git commit -a

Adding an existing project to GitHub using the command line :

>>Add the files in your new local repository. This stages them for the first commit.>>Commit the files that you've staged in your local repository.

>git status:

Task:StatusNote:List the files you've changed and those you still need to add or commit: Commands Used:

git status

Shows you the status of files in the index versus the working directory. 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 log:Task:Note:Shows a listing of commits on a branch including the corresponding details. Commands Used: >git log

Page 12: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

12 Documentation on GIT

>git log -p#It is used to view a patch of what changed in each commit >git log --stat#Its is used to view a summary of which files changed

>git diff: Task:Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory.If we changed something in our file.we can see that changes with the use of 'git diff' command.Commands used: git diff $ID1 $ID2(opt.$FILES) git diff HEAD~ HEAD>As per above log page,we have 4 commitsNote:Now we can view the difference b/w the commits c9668df6 and 78541dd01>We don’t need to type the whole SHA1 hash,.usually the first 7 letters are enough S yntax of git diff: ‘git diff $ID1 $ID2(opt.$FILES)’Note:>>The latest revision (id)is always HEAD and The latest-1 revision is always HEAD~ So we can show the difference b/w the last and the 2nd last commit using ‘ git diff HEAD~ HEAD’ command>Line starts with a minus indicates deleted, or changed lines>Line starts with a plus indicates added, or changed lines

Page 13: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

13 Documentation on GIT

>git tag:Task:A tag is something similar to a pointer.It is used to mark a significant change set, such as a release.Commands used: git tag -l release-candidate* git tag -l>If we want to see all similar tags, type 'git tag -l release-candidate*' (to see all release candidate tags).>we can list all tags using 'git tag -l'Notes: Let’s create a tag for the first commit,we call the tag "init".we create such

"annotated” tags using the -a switch behind git tag.

Page 14: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

14 Documentation on GIT

>git show:Task:We can use git show to show a specific commit.Commands used: 'git show $TAG/$ID'

>So the output is the commit id,the author,the date,the message, and difference to the previous commit(everything is in green color because this was the 1st commit)>>Now GIT knows :init-->the first commit release-candidate(important)--> the latest commit>git branch: Task:List all the branches in your repo, and also tell you what branch you're currently inCommands Used: >git branch >git checkout -b <BranchName> >git branch -d <BranchName>

Page 15: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

15 Documentation on GIT

>git rm:Task:RemoveNote:Removes files from your index and your working directory so they will not be tracked.Commands Used: >git rm filename

>git merge:

Page 16: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

16 Documentation on GIT

Task:Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts. Commands Used: >git merge <BranchName>

>git push:Task:Push Note:Send changes to the master branch of your remote repositoryCommands used: git push origin master

>git fetch:Tasks:Fetches all the objects from the remote repository that are not present in the local one.Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it.Commands Used: >git fetch

>git fetch origin

Page 17: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

17 Documentation on GIT

>git pull: Task: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.Commands Used: >git pull

>git pull origin

>git remote: Task:Shows all the remote versions of the repositoryCommands Used: >git remote

Page 18: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

18 Documentation on GIT

>git remote -v#Its shows the URL’S of each remote server

>git remote show origin#Its shows the state of all remote branches

>echo:Task:It makes some changes to the fileCommands Used: >echo “Log Message” > <filename>

>touch:Task: The touch command is the easiest way to create new, empty files. It is also used to change the time stamps (i.e., dates and times of the most recent access and modification) on existing files and directories.Commands Used: Touch [option] file name(s)

>git revert:

Git revert command is used to revert a particular commit.Most of the times a commit is reverted when it is causing the regression during testing.When git revert is done this itself results in a commit(author as a person who is reverting). 

Usage is as follows:git revert [options] <commit-ish>or: git revert <sub command>

Page 19: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

19 Documentation on GIT

    --quit                end revert or cherry-pick sequence    --continue            resume revert or cherry-pick sequence    --abort               cancel revert or cherry-pick sequence     -n, --no-commit       don't automatically commit    -e, --edit            edit the commit message    -s, --signoff         add Signed-off-by:    -m, --mainline <n>    parent number    --rerere-autoupdate   update the index with reused conflict resolution if           possible    --strategy <strategy>      merge strategy    -X, --strategy-option <option> option for merge strategy

In simple terms to revert a particular commit git revert <commit-id>.This internally creates a separate commit for reverting a previous commit.

>git reset:

Git reset on the other hand is primarily used to  reset the current HEAD to the specified state.git reset is also very helpful in the following scenarios1. When you have made some changes and you no longer wanted them to be committed you just wanted to go back to the older clean stategit reset --hard HEAD2. When you wanted to go to two commits backgit reset --hard HEAD~23. When you are doing git pull. It might result in merging errors. In this case you might just want to get rid of the mess, then you can simply use git reset --hard HEAD4. You might have added a file to commit using  git add abc.cbut later you realized you do not want to add then you can use the followinggit reset -- abc.c>git checkout:

This command checks-out content from the repository and puts it in your work tree. It can also have other effects, depending on how the command was invoked. For instance, it can also change which branch you are currently working on. This command doesn't make any changes to the history.

>git mv

Task: git-mv - Move or rename a file, a directory.

Commands Used: >git mv oldname newnameEx:Consider an example,

Page 20: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

20 Documentation on GIT

>git clean -i:Task:git-clean - Remove untracked files from the working tree <i>=-Show what would be done and clean files interactivelyCommands Used: >git clean - <i> <f> <q> <d>

Page 21: mounikareddyblog.files.wordpress.com€¦ · Web view1.2.Localized or Centralized version control systems -----4 1.3.Distributed version control systems-----5 1.4.Git-----5 2.Tools

21 Documentation on GIT

------------------------------------------------END---------------------------------------------------

Still have some questions?

Send us an email to: [email protected] [email protected]


Recommended