4

Is there a built in option in git cherry-pick to keep the original Author & Committer? without using a script , especially needed when cherry-picking multiple commits.

i have found this script or this But both are over 2 years old

looking at the official documentation i did not see any option am i missing somthing?

galsi
  • 421
  • 1
  • 6
  • 19
  • 3
    Sorry for the question but... why do you need to build a lying history? What is the expected practical benefit here? – Romain Valeri Apr 06 '20 at 07:57
  • i manage central branches for 45 developers , and many cherry-picks go through me in order to keep correct history i must keep original data – galsi Apr 06 '20 at 13:37
  • What are you calling "original data"? Your cherry-picked commits still have their author names and dates, only with the additional info of you committing again at the moment you cherry-pick. IF you ever needed to answer the question "who committed this the first time?" (which is *highly* unlikely), you still would be able to retrieve the info by tracking the source of the cherry-pick and read these (unchanged) data. – Romain Valeri Apr 06 '20 at 14:53
  • "i must keep original data" committer is metadata, who made the actual commit. Cherrypick makes new commits. You're the one doing the cherrypick. You made the new commit. – jthill Apr 06 '20 at 17:34
  • in my case my data only the original committer is not important , because it is saved when i push to the server. – galsi Apr 06 '20 at 18:50

1 Answers1

12

Cherry-picking keeps the author by default anyway so there is nothing to do here.

None of these commands let you keep the committer, but the committer name and email address come from your configuration, where you can lie if you wish, so:

git -c user.name=bogus -c user.email=lie@example.com cherry-pick <hash>

will make the new commit under the given bogus name.

Setting GIT_COMMITTER_DATE in the environment will override the current time as well. In fact, the environment variables are a general purpose mechanism—they're how git filter-branch does its thing. Hence the scripts that you found will work. Why are you worried about them being "over 2 years old" when Git itself is well over a decade old?

torek
  • 448,244
  • 59
  • 642
  • 775
  • 1
    i there a way of getting these values from the commit itself on a single line? – galsi Apr 06 '20 at 18:49
  • What do you mean by "on a single line"? If you want to extract the values from a commit, see the code that `git filter-branch` uses, in `set_ident` and `finish_ident`, in [the filter-branch script](https://github.com/git/git/blob/master/git-filter-branch.sh). – torek Apr 06 '20 at 18:55
  • is it possible to extract the user.name & user.email from commit hash & pipline to create an alias for cherry-pick with commit extract? – galsi Apr 07 '20 at 05:06
  • @galsi: probably not as an *alias*. As a set of shell functions, sure. (You could make a Git alias that invokes these, but for sanity, it's better to put them into a script.) – torek Apr 07 '20 at 05:10
  • it does not change the author of the commit, but it does add a co-author. – bvdb Jan 20 '23 at 13:02