2

I would like to achieve the following:

  1. keep all the change history(or commits) for the files I selected. Some of the files were renamed and some also were moved from another directories.
  2. I would like to remove all the commits that are unrelated to the files I selected from the git log

I tried different approaches, for example this, but it would not keep the whole history

It would work for me even if I have to process files one by one. I do not have many of them. I just cannot find a way to preserve all commits for the files that were renamed and/or moved.

Thanks in advance

jjd
  • 2,158
  • 2
  • 18
  • 31
  • 1
    Would this answer be useful for your use case? [Making git format-patch follow renames like git log --follow](https://stackoverflow.com/a/48062878/9164010) – ErikMD Nov 02 '20 at 19:03
  • @ErikMD, thanks a lot. I will give it a try and let you know – jjd Nov 02 '20 at 22:04
  • @ErikMD, your script worked as charm. Thanks a lot. Though have a question. There is a --follow-renames option in git format-patch command. Do you know if it does what your script do? Here is the link: https://git-scm.com/docs/git-format-patch#Documentation/git-format-patch.txt---find-renamesltngt – jjd Nov 04 '20 at 16:25
  • Also if you provide your comment as an answer, I would choose it as a right one(hopefully with comparison to the --follow-renames option from git format-patch :) ) so it were easier for others to find a solution once they bump into the same issue. Thanks – jjd Nov 04 '20 at 16:28
  • I saw your link, but I guess you meant `--find-renames` (not `--follow-renames`)? anyway this is not the same feature, IIRC `--find-renames` just specifies a threshold for the diff algorithm. Regarding you latest comment, it wouldn't be appropriate for me to repost my answer in this thread (if it were possible), as it is recommended in StackOverflow to just mark your question as a duplicate of the other thread. – ErikMD Nov 04 '20 at 16:55
  • 1
    @ErikMD I would agree with you, but your answer is not accepted as the right one there. I believe it would be difficult for one who is looking for a solution to find the trace of a right answer. Also I do not think it is a duplicate question. As a good example: I also found that question before posting mine(and I agree it is quite close) and I also found your answer, but did not pay attention to it as it was not marked as the correct. Though, no pressure, I just really think it might be beneficial for the community. Anyway, thanks again. It really helped – jjd Nov 06 '20 at 11:34
  • 2
    @ErikMD I disagree that this is a duplicate question (even if it has the same answer) and have voted to reopen it. The 2 questions are asking very different things, and it would be completely appropriate for you to repost your answer from the other question as an answer here. – Old Pro Nov 11 '20 at 22:05

0 Answers0