In large software projects, managing releases and finding specific release commits can be challenging. Me specially often need to switch between different release versions for debugging, testing, or deployment purposes. Manually searching through Git logs to find the exact commit for a specific release can be time-consuming and error-prone.
This script was created to solve these problems by:
- Automating the process of finding release commits.
- Providing an interactive way to select and checkout to specific release commits.
- Streamlining the workflow for developers working with multiple releases.
The Git Commit Selector is a bash script designed to simplify the process of finding and checking out to specific release commits in a Git repository. It addresses common challenges faced by developers when working with multiple releases.
- Automated Release Search: Quickly finds all commits related to a specific release version.
- Interactive Selection: Presents a list of matching commits and allows the user to select one interactively.
- Automatic Checkout: Checks out to the selected commit, saving time and reducing errors.
- Branch Switching: Automatically switches to the specified branch before searching for commits.
- Error Handling: Robust error checking ensures the script fails gracefully with informative messages.
- User-Friendly Interface: Clear prompts and a simple banner make the script easy to use.
- The script first checks if it's run in a Git repository and if the correct number of arguments is provided.
- It then switches to the specified branch if necessary.
- Using Git log commands, it searches for commits containing the specified release version.
- The filtered commits are presented to the user in a numbered list.
- The user can then select a commit number or choose to exit.
- If a commit is selected, the script automatically checks out to that commit.
This tool is particularly useful for teams working on projects with numerous releases, helping to maintain efficiency and reduce the likelihood of errors when navigating between different versions of the codebase.
- Bash shell
- Git installed and configured
Simply download the Bash version of this and execute the following command.
sudo chmod +x gitcs
sudo mv gitcs /usr/local/bin/gitcs
Download the install.sh
script from the repository or directly create it using any text editor.
Open your terminal and navigate to the directory where you saved the install.sh
script. Run the script:
chmod +x install.sh
./install.sh
The script will:
- Clone the repository.
- Make the main script executable.
- Optionally add the script directory to your PATH.
After installation, you can use the script directly by calling:
gitcs
#or
gitcs <branch_name> <release_version>
Go to the Releases page of this repository and download the latest Windows executable gitcs.exe
. then Move the downloaded gitcs.exe to a directory of your choice, e.g., C:\Tools\gitcs
and Add the directory containing gitcs.exe
to your system's PATH environment variable:
- Right-click on 'This PC' or 'Computer' on your desktop or in File Explorer.
- Click on 'Properties'.
- Click on 'Advanced system settings'.
- Click on the 'Environment Variables' button.
- In the 'System variables' section, find the Path variable and click 'Edit'.
- Add the path to the directory where you placed gitcs.exe (e.g.,
C:\Tools\gitcs
). - Click 'OK' to close all dialogs.
Open Command Prompt and type:
gitcs
#or
gitcs <branch_name> <release_version>
Execute the script or executable with two parameters: branch_name
and release_version
. While the release_version
is intended for release identifiers, you can also input any other value as needed. for example, In this scenario, I aim to locate a specific version of IOMAD LMS. I will be searching for a commit that includes the keyword 4.1.3
in the IOMAD_401_STABLE
branch. Once I identify the desired commit, this script will automatically check out to that selected commit.
gitcs IOMAD_401_STABLE "4.1.3"
and here is the result on linux / Mac os x
and here is the result on windows machine
I'm not certain if this is necessary, but in case someone needs it, here are the steps. Below are instructions on how to compile a Python script into standalone executables for both Linux and Windows using PyInstaller
and auto-py-to-exe
- Python Ensure that Python is installed on your system. Python 3.x is recommended. Install Python from python.org if not already installed.
- PyInstaller: This tool converts Python applications into standalone executables for Linux.
pip install pyinstaller
- auto-py-to-exe: This tool provides a graphical interface for converting Python scripts to standalone Windows executables.
pip install auto-py-to-exe
Navigate to the Script Directory: Open your terminal and navigate to the directory where your gitcs.py
script is located.
pyinstaller --clean --onefile gitcs.py
This will generate an executable named gitcs in the dist
directory within your script's directory.Next, you simply need to place the executable in the system path by using the following command.
sudo mv gitcs /usr/local/bin/gitcs
Run the following command to open the graphical interface for auto-py-to-exe
.
auto-py-to-exe
Configure auto-py-to-exe
- Script Location: Select the git_release_finder.py script.
- One File: Check the option to bundle everything into one executable.
- Output Directory: Choose the directory where you want the executable to be saved.
- Console Window/No Console Window: Choose whether you want a console window to appear when running the executable.
- Additional Files: Add any additional files or folders your script requires.
Click the "Convert .py to .exe"
button. This will convert your Python script into a Windows executable and place it in the specified output directory. The next step is to configure your ENV path.