As a wise man once said:
"With great power comes great responsibility" – Benjamin Parker character from Spider-man comics.
This should not be a stranger when dealing with Git, especially when rewriting the commit history.
Whenever you meet one
--force when you're looking for answers on how to do something with Git you should be really careful and read all the details about it before pushing the changes to
master or any other branch that is worked in collaboration with others.
But this time I had a specific need, I was working on a parallel project that already had about 10 commits and while I was checking what I had done with the
log git command, I soon realized that the author had the same username but several e-mails. I had a mix of commits coming from my work and from personal emails.
I do not think this would cause any real problems since I was making a prototype, but I also noticed that my profile's contribution graph did not show any information about these commits because of my email problem.
This led me to think about the most rational solution, saying:
Followed by a Google search on how we can do this, which took me to this Stackoverflow page that had a comment from Tarandeep Singh who did just what I needed.
git filter-branch -f --env-filter "GIT_AUTHOR_NAME = & # 39; yourname & # 39 ;; GIT_AUTHOR_EMAIL = & # 39; [email protected] & # 39 ;; GIT_COMMITTER_NAME = & # 39; yourname & # 39; ; GIT_COMMITTER_EMAIL = & # 39; [email protected]' ;; " BOSS;
And after a quick double check using
log git then I should run:
git push --force origin master
This would ensure that you rewrite all my remote controls
master branch undertakes to show my personal email and username.
Remember, you should be very careful when you use it
git push --forceI did it because I know I'm the only one working on that project, but the use of this command in other situations could cause other problems.
We hope this can help others when they are in this kind of situation 🙂
dev.to is the place where software developers stay in the circuit and avoid career stagnation.
Registering (for free!) Is the first step.