Understanding a Git commit

In this video, we will look at an important property of a Git commit that happens to significantly influence how Git manages branches and how you need to think about branches themselves.

This video is from the full course: Git Basics

https://www.javabrains.io/courses/git…

Get this course and more at https://www.javabrains.io

#java #git #git commit

What is GEEK

Buddha Community

Understanding a Git commit
Madyson  Reilly

Madyson Reilly

1604109000

Best Practices for Using Git

Git has become ubiquitous as the preferred version control system (VCS) used by developers. Using Git adds immense value especially for engineering teams where several developers work together since it becomes critical to have a system of integrating everyone’s code reliably.

But with every powerful tool, especially one that involves collaboration with others, it is better to establish conventions to follow lest we shoot ourselves in the foot.

At DeepSource, we’ve put together some guiding principles for our own team that make working with a VCS like Git easier. Here are 5 simple rules you can follow:

1. Make Clean, Single-Purpose Commits

Oftentimes programmers working on something get sidetracked into doing too many things when working on one particular thing — like when you are trying to fix one particular bug and you spot another one, and you can’t resist the urge to fix that as well. And another one. Soon, it snowballs and you end up with so many changes all going together in one commit.

This is problematic, and it is better to keep commits as small and focused as possible for many reasons, including:

  • It makes it easier for other people in the team to look at your change, making code reviews more efficient.
  • If the commit has to be rolled back completely, it’s far easier to do so.
  • It’s straightforward to track these changes with your ticketing system.

Additionally, it helps you mentally parse changes you’ve made using git log.

#open source #git #git basics #git tools #git best practices #git tutorials #git commit

Git Rebase Tutorial and Comparison with Git Merge

There are many ways of working with git, if they’re clean, and don’t do damages, probably most of them are good.

But same as space vs. tab, in the IT world is a war between fans of rebase, and fans of git merge.

There are tons of arguments about:

-Which way is better?

-Which one is cleaner?

-Which is more comfortable?

-Which one gives a cleaner git graph?

-Why it’s important, and which one is more dangerous?

#quick help #tutorials #git #git branch #git commit #git interactive rebase

7 Best Practices in GIT for Your Code Quality

There is no doubt that Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Still, developers struggle for code quality. Why? They fail to follow git best practices. In this post, I will explain seven core best practices of Git and a Bonus Section.

1. Atomic Commit

Committing something to Git means that you have changed your code and want to save these changes as a new trusted version.

Version control systems will not limit you in how you commit your code.

  • You can commit 1000 changes in one single commit.
  • Commit all the dll and other dependencies
  • Or you can check in broken code to your repository.

But is it good? Not quite.

Because you are compromising code quality, and it will take more time to review codeSo overall, team productivity will be reduced. The best practice is to make an atomic commit.

When you do an atomic commit, you’re committing only one change. It might be across multiple files, but it’s one single change.

2. Clarity About What You Can (& Can’t) Commit

Many developers make some changes, then commit, then push. And I have seen many repositories with unwanted files like dll, pdf, etc.

You can ask two questions to yourself, before check-in your code into the repository

  1. Are you suppose to check-in all these files?
  2. Are they part of your source code?

You can simply use the .gitignore file to avoid unwanted files in the repository. If you are working on more then one repo, it’s easy to use a global .gitignore file (without adding or pushing). And .gitignore file adds clarity and helps you to keep your code clean. What you can commit, and it will automatically ignore the unwanted files like autogenerated files like .dll and .class, etc.

#git basics #git command #git ignore #git best practices #git tutorial for beginners #git tutorials

Myriam  Rogahn

Myriam Rogahn

1599234420

GitHub for Data Scientists: Commit

This article is part of a follow-along series on GitHub collaboration. In this article, we will try to understand commits in detail, like components of a commit, how to delete commit before and after push or how to reset it.

If you are a beginner and want to understand the practical application, I will recommend a quick read into the article, Collaborate on GitHub like Pro: **Part1 **before you start with this article.

The series, Collaborate on GitHub like pro, focus on specific topics:

  1. Getting started on GitHubCollaborate on GitHub like Pro: Part1
  2. **Branching: **Collaborate on GitHub like Pro: Part2
  3. **Commit: **Collaborate on GitHub like Pro: Commit

What is a commit?

Commits are created with the git commit command to capture the state of a project at that point in time. When you make a commit, Git stores a commit object that contains a pointer to the snapshot of the content you staged (indexed), please see below commit stage highlighted in red box.

Image for post

Commit flowchart

Components of a commit:

Let us take a look into the commit object, shown below. I have highlighted the three main components in the commit, hashhead and branch (master).

Image for post

Image for post

Commit Object

Hash: Every commit creates unique hash for the respective commits. These hashes can later be used to revert to that version or find details on the commit. Usually, only the first 7 characters are used to look for respective commit.

Head: Shows which branch you are working on currently. In the above image, head is pointing to master, which means currently you are working on the master branch.

**Branch: **By default, the first line of development (branch) is named as master. All the preceding work on different branches gets merged to master.

To understand this concept further refer to this blog post.

Image for post

Master branch after three commits

Switch to a specific commit

There are multiple ways to checkout to a specific commit based on the use cases. You might want to make a temporary or permanent switch. Sometimes you might want to go a few steps back and maybe add a feature from that step onwards.

#commit-git #git-revert-commit #checkout-git #show-heads #git-delete-branch

Rupert  Beatty

Rupert Beatty

1620451980

How to Use Git Rebase to Squash a Sequence of Commits to a New Base Commit

What is a rebase? 📚

Rebasing is one of the two Git processes of integrating changes from one branch to another.

While merging always moves a branch forward in history by simply adding a new commit representing each branch integration, rebasing can be much more powerful (and dangerous) as it allows us to rewrite history.

Why do we rebase? 🧐

Rebasing is the process of moving or combining (i.e. squashing) a sequence of commits to a new base commit.

Imagine you’re working on a feature branch and after some time you realise the main (aka “master”) branch has been updated by someone else’s code. This means your branch has now diverged from the main branch. At some point, you will want to include said changes in your feature branch. A common way of doing this would be to simply do a git pull from main which would add a merge commit to your feature branch.

#git #git-rebase #github-actions #git-commit