Utoljára aktív 1723350276

Action-bot automated repository can be filled with GA commits, the script would delete GA commits in HEAD until the earliest commit not authored by GA.

Vinfall gist felülvizsgálása 1723350276. Revízióhoz ugrás

1 file changed, 55 insertions

delete-github-action-head-commits.sh(fájl létrehozva)

@@ -0,0 +1,55 @@
1 + #!/bin/bash
2 +
3 + # Usage: action-bot automated repository can be filled with GA commits,
4 + # the script would delete GA commits in HEAD until the earliest commit not authored by GA.
5 + # Author: Vinfall
6 + # License: CC0 (Public Domain)
7 +
8 + # Define a function to delete commits authored by a specific email address
9 + del_ga_commits() {
10 + # Define the email address of the author to be deleted
11 + author_email="[email protected]"
12 +
13 + # Get the HEAD of the current branch
14 + current_commit=$(git rev-parse HEAD)
15 +
16 + # Loop to find the first commit that is not authored by the specified email address
17 + while true; do
18 + # Get the author of the current commit
19 + commit_author=$(git log -1 --pretty=format:"%ae" "$current_commit")
20 +
21 + # If the author is not the specified email address, stop the loop
22 + if [ "$commit_author" != "$author_email" ]; then
23 + break
24 + fi
25 +
26 + # Get the parent commit of the current commit
27 + current_commit=$(git log -1 --pretty=%P "$current_commit")
28 +
29 + # If it has reached the earliest commit, stop the loop
30 + if [ -z "$current_commit" ]; then
31 + echo "No commits authored by GitHub Action in HEAD found, no need to delete."
32 + return
33 + fi
34 + done
35 +
36 + # Get the short version of the commit hash
37 + short_commit=$(git rev-parse --short=8 "$current_commit")
38 +
39 + # Prompt the user to confirm the operation
40 + echo "You are about to delete all commits from HEAD to commit $short_commit. Continue? [y/n] \c"
41 + read -r REPLY
42 + if [[ $REPLY =~ ^[Yy]$ ]]
43 + then
44 + # Reset the main branch to the specified commit
45 + git reset --hard "$current_commit"
46 +
47 + # Push the changes to the remote repository
48 + git push origin main --force
49 + else
50 + echo "Operation canceled."
51 + fi
52 + }
53 +
54 + # Call the function to delete commits authored by a specific email address
55 + del_ga_commits
Újabb Régebbi