How to change author of commit

How to change author of commit

How to change the author of a commit

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

Miquel Canal

4 Easy Steps to Change Author Name of a Commit After Push

The steps above will change the author of a commit. But what is the meaning of each commands above and what it means to change a git repository’s history?

I came across this question recently after changing the settings on GitHub page and seen that commits were logged with invalid an invalid name. Reading through Git’s documentation made it tricky to find the answer. This Stack Overflow answer nail it but I still decided to write about it to review the concepts behind scenes.

What does the rebase commit do?

The rebase command basically integrates changes from one branch into another. It is an alternative to the “merge” command. The difference between rebase and merge is that rebase rewrites the commit history and creates a linear succession of commits, while merging adds a new commit to the destination branch. The image bellow perfectly shows a visual representation of both processes.

Git amend command

The amend command allows git users to change details of a commit. The amend structure is simple:
git commit –amend

This will prompt a vi/vim view where the details of a git commit can be changed:

Change git history… Caution!

Those who are familiar with rebasing know how powerful the tool it is. It might be tempting to use it all the time as well.

When getting conflicts during a rebase, Git pauses on the conflicting commit and allows to fix conflict before proceeding. However, solving conflicts in the middle of a long chain of commits is often confusing and another source of potential errors.

Rebasing creates this linear mind-set and give less priority to the actual goal of git. That is why it is not recommended to change the history of a git repository unless there is no alternative to it.

In my case, I was the only user interacting with the repository so it was safe. However, when multiple developers are working on multiple branches, change to the git history can become a real source of problems.

References

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

How to Change Git User Name and Email

Easy steps to configure a Git repository and change the Git user name and email. A review of git’s config object and how to retrieve information from a git repository using the git config command.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

Github announced its deprecation of user passwords for all Git operations. Git operations that use authentication will require the use of token-based (GitHub User Access Token). The motivation behind this decision from GitHub is to increase user’s security from malicious attackers.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

Angular Nested Routing

Angular is one of the most advanced JavaScript frameworks at the moment. Been able to create nested routings based on modules is key to design an easy to scale Angular application.

This site uses cookies to ensure a great experience. By continue navigating through the site you accept the storage of these cookies.

Treeindev is my personal website. I write articles about best practices in Software Development and cutting-edge Web tools and technologies.

You can find articles of multiple topics. I especially enjoy working with: Angular, React, NodeJS, PHP, Java, HTML5, SASS and MySQL. I am also interested on renewal energy and I share information about software tools used on that industry.

Opinions expressed on this site are my personal point of view. Most of the projects listed here are done in collaboration with other professionals and all rights belong to their respective owners. Credits to teams and organizations are always provided.

How to amend several commits in Git to change author

I have made a series of commits in Git and I realise now that I forgot to set my user name and user email properties correctly (new machine). I have not yet pushed these commits to my repository, so how can I correct these commits before I do so (only the 3 latest commits on the master branch)?

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

8 Answers 8

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Warning: now deprecated in favor of filter-repo.

Rebase/amend seems inefficient, when you have the power of filter-branch at your fingertips:

(split across lines for clarity, but not necessary)

Be sure to inspect the result when you’re done, to make sure that you didn’t change anything you didn’t mean to!

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

The interactive rebase approach is pretty nice when used in conjunction with exec. You can run any shell command against a specific commit or all commits in the rebase.

First set your git author settings

Then to reset the author for all commits after the given SHA

Per @Dave’s comment below, you can also change the author while maintaining the original timestamps with:

How to change the author of a commit in GitHub?

I want to know if there is a way to change the person(account) who pushed changes in a GitHub repository.

For example: I push to my private repository under a different name(not email) but I misspell one letter of my name and GitHub marks the commit as commited by userame not username;

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

3 Answers 3

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

I misspell one letter of my name and GitHub marks the commit

==> in this case, you need rebase.

Pull request task only works on Web GUI, it isn’t Git underlying command.

(1) Delete current Pull request.

(2) Rebase your commit with your wishing identify information (email, name).

(3) Create new Pull request.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

Easy Steps to Change Author Name of a Commit After Push.

Rebase the repository to the previous commit of the one you want to change by running:1 git rebase –i <>

The script above prompts you with a list of your commits in descendent order. On this vi/vim view, replace the word pick to edit per each commit you want to edit. Then quit and save.

How to change the author information in the commit history of a git repository

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

When working on both work-related and personal projects, oftentimes you need to swap back and forth between git credentials in order to push to the corresponding repository. and sometimes, you forget. 🤷‍♂️

In this post, I’ll provide a few different options to quickly change the author name/email for commits in your repository’s history, swapping out the wrong commit author (or incorrect author details) with the correct information. First, we’ll go through some of the safer ways to edit commits, and finally, I’ll share a custom script that will do the heavy-lifting for you.

What are you trying to accomplish?

The way to change commit author information depends on the situation you find yourself in:

Change author info before making a commit

If you need to change your identity before making a commit, there are three ways to update the info. None of the methods listed in this section will impact previous commits, only commits made from this point forward.

Change the author details for the next commit only

Change the author info for the current repository

To change the author information that is used for all future commits in the current repository, you can update the git config settings so that they only apply here:

Change the author name and email globally

Editing the history of previous commits (safely)

So you need to edit the author information of commit(s) that have already been made? First let’s go over the safe(r) methods of editing your commit history.

Edit the last commit

Editing multiple commits with interactive rebase

The easiest (and safest) way to edit the commit history is by using git’s interactive rebase command.

First, find the hash of the commit right before the one you would like to edit and pass it to the rebase command:

Then, mark each commit you would like to modify with the edit keyword:

Git will step you through each commit, allowing you to edit (or not) as you desire:

Run through each of the commits and edit accordingly.

Edit all history using a git filter-branch script (danger-zone)

I have implemented the git filter-branch command into a custom script that can be used in interactive mode, or passively via option flags.

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 rewrite history if absolutely necessary.

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.

Instructions

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

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:

If you prefer to set up the script as a function you can call from anywhere, add the following function to your

You may pass options (as flags) directly to the script, or pass nothing to run the script in interactive mode. All of the available options are outlined below:

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

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

remote

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

force

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

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.

work-tree

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

Git FAQ

Frequently asked questions around Git and Version Control.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

How can I change the author name / email of a commit?

Before we jump into solutions, let’s find out what exactly it is you want to accomplish:
a) Change the author information before making a commit
b) Change the author information after making a commit (i.e. for historical commits)

Let’s look at both cases in detail.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

The Git Cheat Sheet

Changing Your Git Author Identity

There are three ways to change your committer identity in Git. All of these methods only affect future commits, not past ones!

Changing Your Committer Name & Email Globally

Changing Your Committer Name & Email per Repository

Changing Committer Information in Tower

Changing the Author Information Just for the Next Commit

Editing the Author of Past Commits

Editing Past Commits Rewrites History!

There are three basic ways to edit your past commits:

In case you want to change just the very last commit, Git offers a very easy way to do this:

This effectively replaces the last commit with your «edited» version, correcting the wrong author information.

Using Interactive Rebase

Interactive Rebase is the Swiss Army Knife of tools in Git: it allows you to do and change almost anything. However, being as powerful as it is, this also means you can very easily shoot yourself in the foot. Use it with care (and possibly read up on it)!

The first step is to identify the last «good» commit and provide its hash to the rebase command:

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

Your editor will open, requesting you to mark all the commits you want to change with the «edit» keyword.

Git will now walk you through each commit, giving you the chance to mold it as you desire:

Your job, now, is to correct the author information and then continue to the next concerned commit object until you’ve edited all the commits you just marked:

Using git filter-branch

Another way is to use Git’s «filter-branch» command. It allows you to batch-process a (potentially large) number of commits with a script.
You can run the below sample script in your repository (filling in real values for the old and new email and name):

The same warning applies to this method as to the others mentioned: you are rewriting history with this command, creating new commit objects along the way!

Learn More

Get our popular Git Cheat Sheet for free!

You’ll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.

How to change author of commit. Смотреть фото How to change author of commit. Смотреть картинку How to change author of commit. Картинка про How to change author of commit. Фото How to change author of commit

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That’s why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *