Found 56 Articles for Git

Why is git branching fast compared to other version control systems?

kannan sudhakaran
Updated on 20-Feb-2021 08:55:03

277 Views

Branching allows us to diverge from the main line of work and work on something else in isolation. Conceptually, we can think of a branch as a separate isolated workspace. We have a main workspace called the master.We can create a feature branch and work separately on the feature branch to add more features to the project without affecting the main line of work. If there is some error in the feature branch, we can fix it without affecting other collaborator’s work. Once everything is working properly in the feature branch, we can merge it with the main line of ... Read More

How to tag a commit in git?

kannan sudhakaran
Updated on 20-Feb-2021 08:53:33

3K+ Views

The git commit is a 40-digit hexadecimal SHA1 hash. Quite often we need to bookmark a as the commit hash is difficult to memorize. This is where one can use tags. Tags can be used to name a commit. In other words, tags are labels that can be used to identify a specific commit. For e.g., “v1.0, RC1.0” are some ways to name a commit.Tags can be classified as −Lightweight TagsAnnotated TagsLightweight TagsA Lightweight tag is also known as a simple tag. These tags use a name to refer to a specific commit. Lightweight tags are private to a repository. ... Read More

What is the meaning of the ‘detached HEAD’ state in git?

kannan sudhakaran
Updated on 20-Feb-2021 08:52:17

1K+ Views

Explanation − In git HEAD is a reference pointer and points to the current commit in the current branch. The below diagram shows that there are two commits ‘Commit#1’ and ‘Commit#2’, where ‘Commit#2’ is the latest commit. Every commit in Git will have a reference to its previous commit. Here, ‘Commit#2’ will have a reference to ‘Commit#1’. The current branch is master. The master pointer points to the latest commit i.e., ‘Commit#2’. The HEAD points to the master. In other words, the HEAD points to the last commit via the master.To check where the HEAD is pointing to, we can ... Read More

What is the difference between HEAD and master in git?

kannan sudhakaran
Updated on 20-Feb-2021 08:50:31

5K+ Views

A branch in Git is a series of interrelated commits. When a repository is initialized in Git, a branch will be created by default. This default branch is called the master.Multiple branches can be created within a Git repository. When a developer starts working on a new feature of the project, he may create a new feature branch and work in isolation from the master branch. Once the feature is completed changes in that branch will be merged to the master branch. In other words, the master branch will be the main line of work. The master itself is a ... Read More

How do you view the revision history in Git?

kannan sudhakaran
Updated on 20-Feb-2021 08:48:40

959 Views

Let’s say you want to view all commits to the Git repository. The git log command returns all of the commits that have been made to the repository. This command lists the latest commits in chronological order, with the latest commit first.The syntax of the git log command is given below −$ git logThe following screenshot shows how to use the command to view all commits in the current repository.dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo (master) $ git log commit cbc01c8399faf9063eca4ba7781d08eebbe56aaa (HEAD −> master) Author : "Kiran Date: Fri Jan 22 19:38:42 2021 +0530    file2. txt commit 8100770d7274e6bae4e252d7b3c461020b8bc5b2 Author : ... Read More

Difference between a Centralised Version Control System (CVCS) and a Distributed Version Control System (DVCS)

kannan sudhakaran
Updated on 20-Feb-2021 08:46:19

971 Views

A version control system is a software that allows you to manage changes to assets (codebase, files) over a period of time. Centralised and Distributed are the two main types of version control systems. The fundamental difference between these two lies in how they −Manage the repositoriesManage the content workflowCentralised ModelCentralised version control systems follow a server-client model. The server holds a single central copy of the project along with a history of changes made to the code base over a period of time. The basic workflow to work with a centralized version control system is given below −When a ... Read More

What are the best practices for committing in Git?

kannan sudhakaran
Updated on 20-Feb-2021 08:44:41

184 Views

Following are the best practices for committing in Git −Make small, single−purpose commitsCommitting small sections of code helps the team to understand what work has been completed. It is easier to revert smaller commits and helps you maintain a stable codebase. A commit should act like a wrapper around a set of changes. This means that if you are fixing 2 distinct bugs, use 2 different commits. In other words, changes or code that are logically related should be part of a single commit.Commit messages should be short and detailedCommit messages should begin with a short summary of the change. ... Read More

What are the commonly used methods to auto-generate the .gitignore file?

kannan sudhakaran
Updated on 20-Feb-2021 08:42:47

1K+ Views

The .gitignore file is a text file that tells Git which files or folders should be ignored while committing changes to the repository. This file lists the project files that we do not want Git to track for us.Following are the two commonly used methods to auto−generate the .gitignore file −Using the Github SiteThe GitHub Site provides a collection of useful .gitignore templates for different technologies. The below screenshot shows a list of .gitignore templates provided by the site.Let us say you are working on a Java project and would want to add a .gitignore file. All you have to ... Read More

How to ignore a previously committed file in Git repository?

kannan sudhakaran
Updated on 20-Feb-2021 08:39:57

4K+ Views

The .gitignore file does not operate on files that are already committed. To ignore changes to a file that was accidentally staged or committed the following should be done −Step 1 − Remove such files or directories from the staging areaStep 2 − Commit changes in the repositoryStep 3 − Add path of such files or directories in the .gitignore fileStep 4 − Commit changes to the repositoryLet us understand this with an example −Create a folder by the name “bin” in the working directory. Add a file “temp.bin” with some content inside the folder and commit the changes.$ mkdir ... Read More

What is the purpose of the .gitignore file?

kannan sudhakaran
Updated on 20-Feb-2021 08:37:13

1K+ Views

When a Git project is compiled it may generate binary files, lock files, temporary files and metadata files. These are intermediate files that are not part of the source code. For example, IDE config files or intermediate files like “.class”, ”.exe”, “.bin” etc. that are generated during compilation should be ignored by the version control system as they will be different for each developer machine and will unnecessarily increase the size of the repository.The .gitignore is a text file where each line contains a pattern for files or directories to ignore. It is usually placed at the root of the ... Read More

Advertisements