English 中文(简体)
如何更新对作者的承诺,但在修改时保留原来的日期?
原标题:How to update git commit author, but keep original date when amending?
  • 时间:2016-12-23 12:33:35
  •  标签:
  • git

如果承诺已经作出并推向存放处,如果想改变某个特定承诺的作者,我可以这样做:

git commit --amend --reset-author

但是,这将改变最初承诺的日期。

我怎么能够重新打造提交人,而是保留最初的投稿日期?

最佳回答

Hm,最后,我为我找到了比喻容易的解决办法。 我在名录上写了字,其中载有gitrewrite.sh,并修改了许可,以便可以推断出:

$ chmod 700 gitrewrite.sh

然后,我把手稿放在:

#!/bin/sh

git filter-branch --env-filter  
NEW_NAME="MyName"
NEW_EMAIL="[email protected]"
if [ "$GIT_COMMIT" = "afdkjh1231jkh123hk1j23" ] || [ "$GIT_COMMIT" = "43hkjwldfpkmsdposdfpsdifn" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
  --tag-name-filter cat -- --branches --tags

之后,在终点站操作文字:

$ ./gitrewrite.sh

而这是这样。 历史已经改写。

将该守则贴在存放处,并添加force

<>载体>Important note:

对其他人来说,铭记这将在古特历史中产生新的参考资料,而只是在私人存放处或仍然与其他人没有共享的存放处这样做,因为这可能会造成混乱的参考资料!

地雷是私人的雷管,因此没有这方面的担忧。 如果公之于众,那么或许采用其他建议的答复可能是更好的选择。

问题回答

如何使用<代码>rebase,并保留 承诺日期 提交人日期:

git -c rebase.instructionFormat= %s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author  rebase -f <commit/branch before wrong author and email, or --root to rebase all>

如在其他一些答复中所提到的,你可能会使用:

git commit --amend --reset-author --no-edit --date="<old-date>"

在这项工作中,有许多人工复制或打字,以达到旧日期。 您可能希望自动获得这一日期,只读到最后条目的日期:

git log -n 1 --format=%aD

混淆二者,使用一些 she魔:

git commit --amend --reset-author --no-edit --date="$(git log -n 1 --format=%aD)"

这自动确定最后一项承诺的日期,即作为新承诺的日期与已变更的作者一起修改。

如今,根据更多的承诺来改变提交人,例如,你要把提交人放在被人 clo的帽子上,而互动的重新基础是你的朋友:

git rebase -i <commit before wrong author and email>

You then change all commits you want to adjust from pick to edit and save the file. Git stops on every commit to be edited and you rerun:

git commit --amend --reset-author --no-edit --date="$(git log -n 1 --format=%aD)" && 
    git rebase --continue

如果携带少量合理承诺,你可使用<条码>arrow-up重复这一指挥。 直至重基完成的关键。 如果承诺数量较多,打字<条码> 箭-up+return就变得太过激,你可能想制造一个小的手法,重复上述指挥,直到重新基底完成。

  1. 如果你正在做<代码>rebase 然后使用<代码>截至日期-日期-日期>,使日期与以前相同。

    $ git commit --amend --committer-date-is-author-date
    
  2. For normal amend, copy the original committer time and override the time when amending using --date flag.

    $ git log                     # copy the  original-committer-time 
    $ git commit --amend --reset-author --date="<original-committer-time>"
    
    # e.g. git commit --amend --date="Fri Dec 23 18:53:11 2016 +0600"
    

We can get the required behaviour using rebase autosquash:

git commit --fixup HEAD
git rebase --autosquash --committer-date-is-author-date HEAD~2

The first command creates a new commit as a fixup commit on the current HEAD commit. A fixup commit means if rebase is run later with --autosquash, this new commit will be fixed up on the old one (same as fixup in interactive rebase). The second one triggers a rebase onto HEAD~2 - means 2nd level parent of HEAD, or the parent of the original HEAD (before we added the fixup) so this will trigger a rebase with the 2 commits only. Since we added --autosquash, the commits will be squashed together and adding -- committer-date-is-author-date means it will use the date of the original authored commit rather than this current date in which the new commit is really created.

警告: 如果承诺已经推进,如果你以任何方式篡改所推动的承诺并大力推动,你将重写通常被视为非常坏的公开历史。 如果没有人把工作建立在你的承诺之上,这不是一个问题。

错误是使用---reset-author。 http://git-scm.com/docs/git-commit#Documentation/git-commit.txt-authorltgt”rel=“nofollow noreferer”>--author 这样做就足够了:

git commit --amend --author  My Name <[email protected]> 

从上述备选办法的文件可以看出,重新制定方案的办法规定:

这也延长了提交人的时间。

虽然仅仅推翻提交人的备选办法(见, v1.5.0)并没有提到任何这种副作用。

为了改变多重承诺或整个承诺历史,可以使用以下指挥系统:

git rebase -r <commit/branch before wrong author and email or  --root  for all commits> --exec "git commit --amend --no-edit --author  My Name <[email protected]> "

Very similar to @Aleks answer 我发现,解决办法对我来说是最佳的:

https://www.git-tower.com/learn/git/faq/change-author-name-email

您为<代码>确定了数值。 EPAONG_EMAIL,NEW_NAME and NEW_EMAIL 根据您在以下文字中的需求,从贵方项目中管理:

git filter-branch --env-filter  
WRONG_EMAIL="[email protected]"
NEW_NAME="New Name Value"
NEW_EMAIL="[email protected]"

if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
  --tag-name-filter cat -- --branches --tags

WARNING:这将改变作者和电子邮件:all。 承诺地点:<代码> WRONG_EMAIL作为作者出现。

引自

git 过滤器-branch with aplethora of pitfalls [...]. 这些安全和业绩问题不能自成不变,因此建议不使用。 请使用一种替代的历史过滤工具,如 g过滤器。

如果你继续发言,我希望你了解一下你在<条码>git reflog上的道路。 正如“Aleks”已经说过的:在你独自工作的地方,只有做这些事情。

这里的大多数答复对我想要改变旧承诺的作者,而不是最近的承诺,并非完全正确。

www.un.org/Depts/DGACM/index_spanish.htm WARNING: 这将改变各位的作者和承诺,使你们的现用户了解这些承诺。

如果你想要改变一项或多项承诺的提出者和执行者,并保留承诺的原始/历史日期,则主要有: 为了在Github.com正确表明这一点,你实际上必须重新确定每一个单独承诺的基础,否则就象你的新承诺一样老旧。

  1. Ensure the current git author is the one you want to apply to all commits
  2. Select a commit ID BEFORE the commit(s) you want to change the author for
  3. Begin a rebase with git rebase -i <commit_id>
  4. For every commit you edit the line in nano/vim from PICK to EDIT. In vim you can easily do this with :%s/pick /edit /. Then save.
  5. The rebase will stop on every commit and you need to enter a command: export GIT_COMMITTER_NAME=$(git config user.name) && export GIT_COMMITTER_EMAIL=$(git config user.email) && export GIT_COMMITTER_DATE=$(git show --no-patch --format=%aD) && git commit --amend --author="$(git config user.name) <$(git config user.email)>" --no-edit && git rebase --continue
  6. Once you ve done this for every commit, the work should be done. Checking in Github.com you should see the old commits have the correct author and the new commits have the new dates, not the old one.

不用说,你应该在一个可支配的部门这样做,以确保你获得你所期望的结果。





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签