Coder Social home page Coder Social logo

adamdehaven / change-git-author Goto Github PK

View Code? Open in Web Editor NEW
107.0 4.0 18.0 34 KB

Update the commit history of your git repository to resolve incorrect author information.

Home Page: https://www.adamdehaven.com/blog/update-commit-history-author-information-for-git-repository/

License: MIT License

Shell 100.00%
git author commits script

change-git-author's Introduction

Change Git Author

This action is destructive to your repository's history. If you're collaborating on a repository with others, it's considered bad practice to rewrite published history.

You should only do this in an emergency.

Running this script rewrites history for all repository collaborators. After completing these steps, any person with forks or clones must fetch the rewritten history and rebase any local changes into the rewritten history.

Usage

  1. Download the script from GitHub and save it to an easily-accessible directory on your computer.

  2. Change the permissions of the script file to allow it to execute:

    chmod +x /path/to/changeauthor.sh
  3. Navigate into the repository with the incorrect commit history

    cd path/to/repo

    Alternatively, you can run from anywhere by passing the --git-dir and --work-tree flags.

  4. Run the script (with or without flags)

    ./changeauthor.sh [OPTIONS]...

    If you did not change the permissions to allow execution, you can also call the script with either of the following:

    bash ./changeauthor.sh [OPTIONS]...
    
    sh ./changeauthor.sh [OPTIONS]...

    If you run the script with no option flags, you will be prompted for the needed values via interactive prompts. The script will then proceed to update your local repository and push the changes to the specified remote.


If you would like to suppress the git-filter-branch warning, simply add the following line the ~/.bashrc file on your computer:

export FILTER_BRANCH_SQUELCH_WARNING=1

If you prefer to set up the script as a function you can call from anywhere, add the following function to your ~/.bashrc file:

function changegitauthor() {
  # Update the path to point to the absolute path of the script on your computer
  bash /c/absolute/path/to/change-git-author/changeauthor.sh "$@"
}

Options

You may pass options (as flags) directly to the script, or pass nothing to run the script in interactive mode.

old-email

The old/incorrect email address of the author you would like to replace in the commit history.

new-email

The new/corrected email address to replace in commits matching the old-email address.

new-name

  • Usage: -n, --new-name
  • Example: Marty McFly

The new/corrected name for the new commit author info. (Be sure to enclose name in quotes)

remote

  • Usage: -r, --remote
  • Default: origin
  • Example: github

The name of the repository remote you would like to alter.

force

  • Usage: -f, --force

Allows the script to run successfully in a non-interactive shell (assuming all required flags are set), bypassing the confirmation prompt.

If you do not pass a value to the --remote flag when using --force, the default remote (origin) will be used.

WARNING

By passing the --force flag (along with all other required flags), there is no turning back. > Once you start the script, the process will start and can severely damage your repository if used incorrectly.

git-dir

  • Usage: -d, --git-dir

Set the path to the repository (".git" directory) if it differs from the current directory. It can be an absolute path or relative path to current working directory.

This option should be used in conjunction with the --work-tree flag.

work-tree

  • Usage: -w, --work-tree

Set the path to the working tree. It can be an absolute path or a path relative to the current working directory.

help

  • Usage: -h, -?, --help

Show the help content.

version

  • Usage: -v, -V, --version

Show version information.

change-git-author's People

Contributors

adamdehaven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

change-git-author's Issues

Unable to run on OSX

This is really nice but it doesn't seem to work for me? I'm on the latest OSX version using bash locally for my shell. Nothing fancy going on.

However when I run the script I see a couple different errors depending on how I choose to run it. I'm not a bash expert so I may be overlooking something here. 😁

I confirmed it's marked as executable

repo on  master [$?] via ⬢ v10.18.1 
❯ ls -l
total 1104
-rw-r--r--     1 cbzehner  staff    2514 Nov 10 21:19 README.md
-rwxr-xr-x     1 cbzehner  staff   17805 Nov 10 22:04 changeauthor.sh

Just trying to run it as expected

repo on  master [$?] via ⬢ v10.18.1 
❯ ./changeauthor.sh -o [email protected] -e [email protected]
: No such file or directory

Calling it with bash directly gives a different error

repo on  master [$?] via ⬢ v10.18.1 took 2s 
❯ bash changeauthor.sh 
: command not foundne 2: 
: command not foundne 9: 
: command not foundne 11: 
: command not foundne 24: 
: command not foundne 31: 
: command not foundne 34: 
: command not foundne 36: 
'hangeauthor.sh: line 43: syntax error near unexpected token `in
'hangeauthor.sh: line 43: `  case "$1" in

Change user name only

I my case I had to change the user name while keeping the same email address.
Thus, I have commented the lines checking [ "$USER_OLD_EMAIL" == "$USER_NEW_EMAIL" ] and everything has been successfully renamed. 👍

I think, in interactive mode, the script should warn and ask the user if the intention is actually to change the user name while keeping the same email address.

A command line argument may also be added for that case where only one email address is requested.

Showing 2 timelines in GitHub network graph

Hey, Thanks for creating this useful tool.
I recently used it and saw that it creates new network graph and the old one still persists.
Here is a link to my GitHub repo.
Is there any workaround for this?

integer expression expected

test on 5.1.8 and 3.2.57 of Bash
foo unset
/bin/bash -c '[ "$foo" -eq 0 ]' will cause the error
work if change -eq to =

Repository must have a remote setup to run

Just a quick note for your consideration. I ran changeauthor.sh against a local git repository without any remotes set up and it exited early at the VALID_REMOTES check.

I just commented out that section and proceeded as planned, but I want to bring this up in case you haven't encountered this case before.

change author with space in e-mail

Hello,

first thank you for your script, it fixed some e-mail problemes in my git repo.

But i have one commiter e-mail with a space in it.
e.g. Name @example.com.
If i set the old-email to Name @example.com he takes only Name.
If i set Name\ @example.com he takes the space, but i think the check fails.
USER_OLD_EMAIL_EXISTS="$(git ${USER_GIT_DIR} ${USER_WORK_TREE} log --pretty=format:"%ae" | grep -wxi ${USER_OLD_EMAIL})"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.