1+ #! /bin/bash
2+ 
3+ #  Strip Co-authored-by lines from commits authored by current user on current branch
4+ #  Excludes merge commits and commits from other authors
5+ 
6+ set  -e
7+ 
8+ #  Get current branch and user info
9+ CURRENT_BRANCH=$( git branch --show-current) 
10+ USER_NAME=$( git config user.name) 
11+ USER_EMAIL=$( git config user.email) 
12+ 
13+ echo  " Current branch: $CURRENT_BRANCH " 
14+ echo  " User: $USER_NAME  <$USER_EMAIL >" 
15+ echo  " " 
16+ 
17+ #  Get commits by current user on current branch (excluding merges)
18+ COMMITS=$( git log --format=" %H" " $USER_NAME " $CURRENT_BRANCH  ^main) 
19+ 
20+ if  [ -z  " $COMMITS " ;  then 
21+  echo  " No commits by $USER_NAME  found on branch $CURRENT_BRANCH " 
22+  exit  0
23+ fi 
24+ 
25+ echo  " Found commits by $USER_NAME  on $CURRENT_BRANCH :" 
26+ git log --oneline --author=" $USER_NAME " $CURRENT_BRANCH  ^main
27+ echo  " " 
28+ 
29+ #  Check if any commits have Co-authored-by lines
30+ HAS_COAUTHOR=false
31+ for  commit  in  $COMMITS ;  do 
32+  if  git show --format=" %B" " $commit " |  grep -q " ^Co-authored-by:" ;  then 
33+  HAS_COAUTHOR=true
34+  break 
35+  fi 
36+ done 
37+ 
38+ if  [ " $HAS_COAUTHOR " =  false  ];  then 
39+  echo  " No Co-authored-by lines found in your commits on this branch." 
40+  exit  0
41+ fi 
42+ 
43+ echo  " Found Co-authored-by lines in some commits. Proceeding with cleanup..." 
44+ echo  " " 
45+ 
46+ #  Create a backup branch
47+ BACKUP_BRANCH=" ${CURRENT_BRANCH} -backup-$( date +%s) " 
48+ git branch " $BACKUP_BRANCH " 
49+ echo  " Created backup branch: $BACKUP_BRANCH " 
50+ echo  " " 
51+ 
52+ #  Process commits in reverse order (oldest first)
53+ COMMITS_REVERSE=$( echo " $COMMITS " |  tac) 
54+ 
55+ for  commit  in  $COMMITS_REVERSE ;  do 
56+  #  Get the commit message
57+  COMMIT_MSG=$( git show --format=" %B" " $commit " ) 
58+  
59+  #  Check if this commit has Co-authored-by lines
60+  if  echo  " $COMMIT_MSG " |  grep -q " ^Co-authored-by:" ;  then 
61+  echo  " Processing commit: $( git show --format=" %h %s" " $commit " ) " 
62+  
63+  #  Remove Co-authored-by lines from commit message
64+  CLEAN_MSG=$( echo " $COMMIT_MSG " |  grep -v " ^Co-authored-by:" |  sed ' /^$/N;/^\n$/d' ) 
65+  
66+  #  Amend the commit with clean message
67+  git commit --amend --no-edit --message=" $CLEAN_MSG " 
68+  
69+  echo  "  ✓ Removed Co-authored-by lines" 
70+  fi 
71+ done 
72+ 
73+ echo  " " 
74+ echo  " ✅ Successfully stripped Co-authored-by lines from your commits on $CURRENT_BRANCH " 
75+ echo  " 📦 Backup created at: $BACKUP_BRANCH " 
76+ echo  " " 
77+ echo  " To restore if needed: git reset --hard $BACKUP_BRANCH " 
78+ echo  " To delete backup: git branch -D $BACKUP_BRANCH " 
0 commit comments