bg_image
header

Conventional Commits

Conventional Commits are a simple standard for commit messages in Git that propose a consistent format for all commits. This consistency facilitates automation tasks such as version control, changelog generation, and tracking changes.

The format of Conventional Commits follows a structured pattern, typically as:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Components of a Conventional Commit:

  1. Type (Required): Describes the type of change in the commit. Standard types include:

    • feat: A new feature or functionality.
    • fix: A bug fix.
    • docs: Documentation changes.
    • style: Code style changes (e.g., formatting) that don't affect the logic.
    • refactor: Code changes that neither fix a bug nor add features but improve the code.
    • test: Adding or modifying tests.
    • chore: Changes to the build process or auxiliary tools that don't affect the source code.
  2. Scope (Optional): Describes the section of the code or application affected, such as a module or component.

    • Example: fix(auth): corrected password hashing algorithm
  3. Description (Required): A short, concise description of the change, written in the imperative form (e.g., “add feature” instead of “added feature”).

  4. Body (Optional): A more detailed description of the change, providing additional context or technical details.

  5. Footer (Optional): Used for notes about breaking changes or references to issues or tickets.

    • Example: BREAKING CHANGE: remove deprecated authentication method

Example of a Conventional Commit message:

feat(parser): add ability to parse arrays

The parser now supports parsing arrays into lists.
This allows arrays to be passed as arguments to methods.

BREAKING CHANGE: Arrays are now parsed differently

Benefits of Conventional Commits:

  • Consistency: A uniform format for commit messages makes the project history easier to understand.
  • Automation: Tools can automatically generate versions, create changelogs, and even release builds based on commit messages.
  • Traceability: It becomes easier to track the purpose of a change, especially for bug fixes or new features.

Conventional Commits are especially helpful in projects using SemVer (Semantic Versioning) because they enable automatic versioning based on commit types.

 

 

 


Interactive Rebase

An Interactive Rebase is an advanced feature of the Git version control system that allows you to revise, reorder, combine, or delete multiple commits in a branch. Unlike a standard rebase, where commits are simply "reapplied" onto a new base commit, an interactive rebase lets you manipulate each commit individually during the rebase process.

When and Why is Interactive Rebase Used?

  • Cleaning Up Commit History: Before merging a branch into the main branch (e.g., main or master), you can clean up the commit history by merging or removing unnecessary commits.
  • Reordering Commits: You can change the order of commits if it makes more logical sense in a different sequence.
  • Combining Fixes: Small bug fixes made after a feature commit can be squashed into the original commit to create a cleaner and more understandable history.
  • Editing Commit Messages: You can change commit messages to make them clearer and more descriptive.

How Does Interactive Rebase Work?

Suppose you want to modify the last 4 commits on a branch. You would run the following command:

git rebase -i HEAD~4

Process:

1. Selecting Commits:

  • After entering the command, a text editor opens with a list of the selected commits. Each commit is marked with the keyword pick, followed by the commit message.

Example:

pick a1b2c3d Commit message 1
pick b2c3d4e Commit message 2
pick c3d4e5f Commit message 3
pick d4e5f6g Commit message 4

2. Editing Commits:

  • You can replace the pick commands with other keywords to perform different actions:
    • pick: Keep the commit as is.
    • reword: Change the commit message.
    • edit: Stop the rebase to allow changes to the commit.
    • squash: Combine the commit with the previous one.
    • fixup: Combine the commit with the previous one without keeping the commit message.
    • drop: Remove the commit.

Example of an edited list:

pick a1b2c3d Commit message 1
squash b2c3d4e Commit message 2
reword c3d4e5f New commit message 3
drop d4e5f6g Commit message 4

3. Save and Execute:

  • After modifying the list, save and close the editor. Git will then execute the rebase according to the specified actions.

4. Resolving Conflicts:

  • If conflicts arise during the rebase, you'll need to resolve them manually and then continue the rebase process with git rebase --continue.

Important Considerations:

  • Local vs. Shared History: Interactive rebase should generally only be applied to commits that have not yet been shared with others (e.g., in a remote repository) because rewriting history can cause issues for other developers.
  • Backup: It's advisable to create a backup (e.g., through a temporary branch) before performing a rebase, so you can return to the original history if something goes wrong.

Summary:

Interactive rebase is a powerful tool in Git that allows you to clean up, reorganize, and optimize the commit history. While it requires some practice and understanding of Git concepts, it provides great flexibility to keep a project's history clear and understandable.

 

 

 

 


Atomic Commit

Atomic Commits are a concept in version control systems that ensure that all changes included in a commit are applied completely and consistently. This means that a commit is either fully executed or not executed at all—there is no intermediate state. This property guarantees the integrity of the repository and prevents inconsistencies.

Key features and benefits of Atomic Commits include:

  1. Consistency: A commit is only saved if all changes included in it are successful. This ensures that the repository remains in a consistent state after each commit.

  2. Error Prevention: If an error occurs (e.g., a network problem or a conflict), the commit is aborted, and the repository remains unchanged. This prevents partially saved changes that could lead to issues.

  3. Unified Changes: All files modified in a commit are treated together. This is particularly important when changes to multiple files are logically related and need to be considered as a unit.

  4. Traceability: Atomic Commits facilitate traceability and debugging since each change can be traced back as a coherent unit. If an issue arises, it can be easily traced back to a specific commit.

  5. Simple Rollbacks: Since a commit represents a complete unit of change, unwanted changes can be easily rolled back by reverting to a previous state of the repository.

In Subversion (SVN) and other version control systems like Git, this concept is implemented to ensure the quality and reliability of the codebase. Atomic Commits are particularly useful in collaborative development environments where multiple developers are working simultaneously on different parts of the project.