0

I recently share my laravel project on github using PhpStorm. I afraid why PhpStorm is using hackerrank as git user on my project?

hackerrank Removed h3 commented code.

This is the recently commit I have pasted above. All commits are with the hackerrank user.

Repository is private so I can't share.

kostix
  • 51,517
  • 14
  • 93
  • 176
Asif Mushtaq
  • 3,658
  • 4
  • 44
  • 80

2 Answers2

2

I would roll like this:

  1. Change user name and e-mail.

    Supposedly you want to do this locally in your Laravel project.

    cd to that project's directory and run

    $ git config --local user.name Asif
    $ git config --local user.email asif@example.com
    
  2. Re-write your commits in order to update their metadata:

    $ git filter-branch --env-filter '
        GIT_AUTHOR_NAME=Asif
        GIT_AUTHOR_EMAIL=asif@example.com
        GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
        GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
        export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
        export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
       ' -- --all
    

    (See git help filter-branch for more info.)

  3. Force-push the updated history to Github.

Note that merely running git commit --amend as suggested elsewhere is not going to work for two reasons:

  • It does not change the author's parameters — unless the --reset-author command-line option was supplied.
  • It does nothing to commits down the history chain.
kostix
  • 51,517
  • 14
  • 93
  • 176
0

You can set your user with:

git config --global user.name "John Doe"
git config --global user.email me@me.com

And then amend your commit with reset-author (thanks to kostix' comment)

git commit --amend --no-edit --reset-author

This will set your user correctly for the last commit.

For a specific commit/author, you should take a look at this answer.

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
  • 1
    I believe the question is not how to change the name, but what could have set it to "hackerrank" – lucidbrot Oct 15 '18 at 16:45
  • Oh thanks. I'll let my answer for the time op can see it, and delete it afterward if he doesn't say anything. – Ulysse BN Oct 15 '18 at 16:46
  • @lucidbrot, if so, I'd be tempted to remove the `git` tag as Git won't change anything related to _this_ bit of configuration under no known circumstances. Otherwise, the question may also ask how to "undo" this feat of whatever piece of software did it (I suppose it's PhpStorm). – kostix Oct 15 '18 at 16:57
  • Please note that w/o the `--reset-author` command-line option, the author of the rebased commit won't be changed. – kostix Oct 15 '18 at 16:58
  • @kostix I am obviously not sure how it was meant. But the git tag might be justified if e.g. the user setting can be changed by adding a config file to the index – lucidbrot Oct 15 '18 at 17:07
  • 3
    @lucidbrot, see, if we were to nitpick, the question does not even contain any question. I reckon, English is supposedly not the author's native language, so we sorta should guess a little bit. That what I did. – kostix Oct 15 '18 at 17:16
  • Sorry both of you about my English. I want to know that who did this? and how to stop in the future projects? – Asif Mushtaq Oct 15 '18 at 18:29
  • 1
    Clearly, the name `hakerrank` is unlikely to be assigned automatically by any kind of software I can think of. I'd hence start working from there. Supposedly you did something related to that site's tasks, right? – kostix Oct 15 '18 at 18:54
  • Oh I got it. I took a test on hakerrank a long ago in which one step was about to commits using their details. Thanks. – Asif Mushtaq Oct 18 '18 at 08:06