0

I have a problem I cannot find solution to. I have made a lot of commits to my repo with a different name than my actual name on GitHub, so it didn't track those commits. Now, I have read that it can be changed retrospectively using different options, however each option I tried, despite being successful in terminal, didn't get reflected on a GitHub page. Problem is, I was committing under different name than I should have been, however email address was correct. Could this have had an impact on this?

to give an example without using my details:

  • Used: name - X email - Z
  • Should have used, and changed to: name - Y email - Z

funny thing also, after I ensure, that all my machines that I use are set to Y & Z, I did some commits from them too. some were coming through as Y & Z and some as X & Z, like it wasn't updated straight away. Right now, I believe all machines I use are fine and commits are coming through as Y & Z, but I still need to find a way to change previous commit's name X to Y.

Anyway I need a solution, so all and any ideas are welcome.

Last thing I tried was this: How to change the author and committer name and e-mail of multiple commits in Git?

Thank you.

1615903
  • 32,635
  • 12
  • 70
  • 99
Gregory Sky
  • 140
  • 9
  • possibly solved here: https://stackoverflow.com/a/3042512/12019063 – elmo26 Jul 23 '20 at 15:20
  • i dont think this question has anything to do with android, it's just git – a_local_nobody Jul 23 '20 at 15:22
  • @elmo26 - I haven't tried that solution yet, I will give it a try later on and let you know! – Gregory Sky Jul 23 '20 at 15:25
  • 1
    @a_local_nobody - I tagged all systems I use git on – Gregory Sky Jul 23 '20 at 15:25
  • Be aware that when you do this, you are not actually *changing a commit*. You are instead making a *new* commit that's a lot like the previous commit, but has something different about it—such as your name and/or email address. This *new* commit has a different hash ID. Since Gits agree on commits by *hash ID* you must get everyone who was using the old commit to switch over to using the new commit instead. (The old commit continues to exist for as long as any Git keeps using it.) – torek Jul 24 '20 at 01:48
  • @torek Thank for that, I managed to get that info on my own, and it is acceptable. – Gregory Sky Jul 25 '20 at 08:58

1 Answers1

0

The link you pasted is correct : it allows to completely rewrite the history on a local clone.

If your history is shared with a central repo (github) and several devices, you will also need to update the history on all these devices.


Here is a list of steps :

From all devices :

  1. make sure you have pushed to github all the commits you want from all devices

On one of your devices (any one) :

  1. make sure to have all the commits locally, and that all the local branches are up to date with their remote counterpart (git fetch, git pull ...),
  2. rewrite the history (for example, using git filter-branch as in the question you quote), and push --force all branches and tags that need to be updated to github

On all devices :

  1. fetch the changes from github : git fetch origin

  2. for all local branches which are linked to a remote branch, run :

     git checkout branch_name
     git rebase origin/branch_name
    
  3. if you have local branches which are not shared, make sure these branches do not have "X Z" commits


Variants :

  • if one of your device only has a local clone, and no local modifications/no local files, you can achieve the same result as steps '4..6' by deleting and re-cloning your central repo
  • using git rebase in step 5 allows to have a warning if some change on the local device is not shared ; a more straightforward command would be git reset --hard origin/branch_name, but this one will delete any change without warning
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thank you for your answer. This is exactly what I did. I also later figured out that in one of my config files, for some reason I still have wrong name and it wouldn't change via command line, so had to use vim to manually change it. ever since, all is good :) – Gregory Sky Jul 25 '20 at 09:03