使用'git filter-branch'来更正最近N次提交中的提交者日期? [英] Use 'git filter-branch' to correct committer dates in last N commits?

查看:591
本文介绍了使用'git filter-branch'来更正最近N次提交中的提交者日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近需要使用'git am'将16个补丁应用到我的回购库中,并且我非常小心地为每个补丁使用'--committer-date-is-author-date'。但是,我还需要调整每个amd补丁的提交消息,并且 - 在完成所有16个补丁之后 - 我发现'commit --amend'碰撞了每个补丁的时间戳。



我终于明白,我的问题可以一举解决, git rebase --committer-date-is-author-date< SHA-commit-before-patches-patches>

但是在尝试用'filter-branch'解决我的问题之前没有解决问题。我很好奇我做错了什么。这是我的尝试:

  git filter-branch --env-filter \ 
'export GIT_COMMITTER_DATE = $ GIT_AUTHOR_DATE 'SHA1..HEAD

结果如下:

 重写1c52265d1f06bd67e0fed1c09e1e75249424476e(1/15)/ usr / lib / git-core / git-filter-branch:1:export:-0500:bad variable name 

我做错了什么?我不允许在env-filter中设置/导出一个变量作为另一个变量的值吗?请注意,如果$ GIT_COMMIT匹配特定的SHA,我将自己的方法从一个有条件地更改为GIT_AUTHOR_DATE和GIT_COMMITTER_DATE的方法调整,但在这种情况下,两个GIT _ * _ DATE变量都设置为常量字符串,而不是另一个变量。 b $ b

解决方案> $ GIT_AUTHOR_DATE 的值包含空格,所以您必须引用它( -0500 是你的时区偏移量):

  git filter-branch  - env-filter \ 
'export GIT_COMMITTER_DATE =$ GIT_AUTHOR_DATE'SHA1..HEAD


I recently needed to apply 16 patches to my repo, using 'git am', and I was careful to use '--committer-date-is-author-date' for each one. However, I also needed to adjust the commit message for each am'd patch, and-- after I was done with all 16-- I discovered that 'commit --amend' bumped the committer timestamp for each of them.

I eventually learned that my problem could be solved in one fell swoop with

git rebase --committer-date-is-author-date <SHA-of-commit-prior-to-patches>

but not before trying to solve my problem with 'filter-branch', which did not work. I am curious what I did wrong. Here is my attempt:

git filter-branch --env-filter \
    'export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE' SHA1..HEAD

And here is the result:

Rewrite 1c52265d1f06bd67e0fed1c09e1e75249424476e (1/15)/usr/lib/git-core/git-filter-branch: 1: export: -0500: bad variable name

What did I do wrong? Am I not allowed to set/export one variable to be the value of another, within an env-filter? Note that I adapted my approach from one that conditionally changed both GIT_AUTHOR_DATE and GIT_COMMITTER_DATE if $GIT_COMMIT matched a particular SHA, but in that case both GIT_*_DATE variables were being set to a constant string, rather than another variable.

解决方案

The value of $GIT_AUTHOR_DATE contains spaces, so you have to quote it (-0500 is your time zone offset):

git filter-branch --env-filter \
  'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' SHA1..HEAD

这篇关于使用'git filter-branch'来更正最近N次提交中的提交者日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆