Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:48:30+00:00 2026-05-29T10:48:30+00:00

I have a script that is automating author re-writes on a number of git

  • 0

I have a script that is automating author re-writes on a number of git repositories.

def filter_history(old, new, name, repoPath):

command = """--env-filter '
        an="$GIT_AUTHOR_NAME"
        am="$GIT_AUTHOR_EMAIL"
        cn="$GIT_COMMITTER_NAME"
        cm="$GIT_COMMITTER_EMAIL"

        if [[ "$GIT_COMMITTER_NAME" = "|old|" ]]
        then
            cn="|name|"
            cm="|new|"
        fi

        if [[ "$GIT_AUTHOR_NAME" = "|old|" ]]
        then
            an="|name|"
            am="|new|"
        fi

        export GIT_AUTHOR_NAME="$an"
        export GIT_AUTHOR_EMAIL="$am"
        export GIT_COMMITTER_NAME="$cn"
        export GIT_COMMITTER_EMAIL="$cm"
'
"""

#DO string replace
command = command.replace("|old|", old)
command = command.replace("|new|", new)
command = command.replace("|name|", name)

print "git filter-branch -f " + command

process = subprocess.Popen(['git filter-branch -f', command],cwd=os.path.dirname(repoPath), shell=True)
process.wait()

The command executes fine, but tells me that nothing changed in the repo history. However, if I take the command that is printed out (which should be what is being executed), drop it in a shell script, and execute it, it changes the history fine. I think that the command is somehow not being executed correctly. Is there any way for be to see exactly what command the subprocess module is executing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:48:31+00:00Added an answer on May 29, 2026 at 10:48 am

    When you use shell = True, subprocess.Popen expects a string as its first argument. It is better not to use shell = True if you can help it, since it can be a security risk (see the Warning.

    When you omit shell = True, or use shell = False, subprocess.Popen expects a list of arguments. You can generate that list of arguments from a string using shlex.split:

    import shlex
    import subprocess
    
    def filter_history(old, new, name, repoPath):
        """Change author info
        """
        # http://help.github.com/change-author-info/
        # http://stackoverflow.com/a/3880493/190597
        command = """git filter-branch -f --env-filter '
            an="$GIT_AUTHOR_NAME"
            am="$GIT_AUTHOR_EMAIL"
            cn="$GIT_COMMITTER_NAME"
            cm="$GIT_COMMITTER_EMAIL"
    
            if [[ "$GIT_COMMITTER_NAME" = "{old}" ]]
            then
                cn="{name}"
                cm="{new}"
            fi
    
            if [[ "$GIT_AUTHOR_NAME" = "{old}" ]]
            then
                an="{name}"
                am="{new}"
            fi
    
            export GIT_AUTHOR_NAME="$an"
            export GIT_AUTHOR_EMAIL="$am"
            export GIT_COMMITTER_NAME="$cn"
            export GIT_COMMITTER_EMAIL="$cm"
          '
          """.format(old = old, new = new, name = name)
    
        process = subprocess.Popen(
            shlex.split(command),
            cwd = os.path.dirname(repoPath))
        process.communicate()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that takes a table name and generates a control file
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that renders graphs in gnuplot. The graphs all end up
I have a script that works fine on my test server (using IIS6). The
I have a script that successfully encrypts a credit card. I need it to
I have an script that receives an encrypted url and from that generates a
I have a script that needs to extract data temporarily to do extra operations
I have a script that takes a command and executes it on a remote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.