#!/bin/bash parent_branch="${1:-master}" # Switch to the root directory of the Git repository cd "$(git rev-parse --show-toplevel)" # Check if there are any uncommitted changes if [[ -n $(git status -s) ]]; then echo "There are uncommitted changes in the branch. Please commit or stash them before running this script." exit 1 fi # Get the list of files that have been modified in the current branch changed_files=$(git diff --name-only "$parent_branch") #echo $changed_files; exit; # Stage the modified files git add $changed_files composer style # Revert any modified files that are not in the changed_files list unstaged_files=$(git ls-files -m | grep -v "$(printf '%s\n' $changed_files)") if [ -n "$unstaged_files" ]; then git checkout -- $unstaged_files count=$(echo "$unstaged_files" | wc -l) echo "The $count files have been reverted:" else echo "No files have been reverted." fi