-2

I am trying to change the author name of the pushed commits on GitHub. I am following the instructions here step by step: https://help.github.com/articles/changing-author-info/#platform-windows but I am stuck at step 3. I am currently using the command prompt on Windows to do it.

#!/bin/sh

git filter-branch --env-filter $' OLD_EMAIL=“yongjeffrey@hotmail.com" CORRECT_NAME=“Jeffrey Yong" CORRECT_EMAIL=“jeffreyyong10@gmail.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]

then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then

  export GIT_AUTHOR_NAME="$CORRECT_NAME"  export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags

So I literally copied and pasted the code above in my command prompt and pressed enter but it seems like there's an error. I already have Cygwin installed and I am wondering what is the best way to run the code above.

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
gogofan
  • 533
  • 1
  • 10
  • 20
  • Does this answer your question? [How to run .sh on Windows Command Prompt?](https://stackoverflow.com/questions/26522789/how-to-run-sh-on-windows-command-prompt) – Michael Freidgeim Mar 05 '21 at 05:57

2 Answers2

3
  1. Create a file named shellpro.sh with the above code in your project directory
  2. Open cygwin
  3. Browse to the project directory using cd command
  4. Type bash shellpro.sh to execute your script

Or you can simply create the file in the project folder and double click it to execute it with git-bash (CygWin in windows)

Gautam Krishna R
  • 2,388
  • 19
  • 26
  • Hi thank you for your reply, I followed your instruction but I am getting this error: `Rewrite f66896628ba48d082c40d06c1ee8020df0d2ec9f (1/29) (0 seconds passed, remaining 0 predicted) C:\Program Files\Git\mingw64/libexec/git-core\git-filter-branch: eval: line 357: unexpected EOF while looking for matching `"' C:\Program Files\Git\mingw64/libexec/git-core\git-filter-branch: eval: line 358: syntax error: unexpected end of file` – gogofan Sep 03 '16 at 14:29
0

I realize this is somewhat ancient but I hit this issue. Git for Windows's bash environment on Windows 10 is a custom Cygwin environment (it seems).

I did the following to get some information on how Git sees it's environment when inside filter-branch:

git filter-branch --env-filter "printenv; echo" -- HEAD~..HEAD

This shows all sorts of handy paths like OLDPWD. But I think it's safest to put your script somewhere in your PATH.

So let's say %USERPROFILE%\bin is in your path go and you put your script in %USERPROFILE%\bin\filterscript.sh

#!/bin/bash

OLD_EMAIL="yongjeffrey@hotmail.com"
CORRECT_NAME="Jeffrey Yong"
CORRECT_EMAIL="jeffreyyong10@gmail.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi

if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then
  export GIT_AUTHOR_NAME="$CORRECT_NAME"
  export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi

You can then invoke it like this:

git filter-branch --env-filter "source filterscript.sh" --tag-name-filter cat -- --branches --tags

Note the use of source. The script needs to be sourced otherwise the environment changes will be lost with the child shell executing the script terminates. Sourcing makes the sh instance that will later execute the commit get the environment changes. It's particularly painful if source is omitted because when debugging it seems that the script is indeed executing (and it is) but not in the right shell.

Tyler Szabo
  • 986
  • 1
  • 7
  • 23