1

I want to prepend some content to the initial state of my code in git.

I have been developing a personal project for a few months, I wanted to push it to a repository and I noticed I have forgotten to put the copyright notice on top of the code files.

So I was wondering if it's possible to add the copyright header to the files in their initial commit and have them be present in all the later commits?

Abcd Efg
  • 2,146
  • 23
  • 41
  • 2
    If I understand correctly your issue, you want to add a changed file to an older commit in Git. You could try the solution: https://stackoverflow.com/questions/2719579/how-to-add-a-changed-file-to-an-older-not-last-commit-in-git – Thân LƯƠNG Đình Sep 01 '20 at 14:54

1 Answers1

0

You cannot change any commit at all—so, no, there is no way to do this.

On the other hand, there's no requirement that you keep using those original commits. Suppose you had your Git take each commit and copy it to a new-and-improved (but different) commit, with a different hash ID, such that the new-and-improved commits have the adjusted file contents?

This new Git repository would be incompatible with the old one. That means any clones of the old repository are also incompatible with the new one. Everyone who has such a clone must throw it out and start over with the new repository.

This—replacing the old repository with a new-and-improved one, where all commits have new and different hash IDs—is what you can do. As for how you can do it, there are lots of ways: Git is a set of tools (like a machine shop) that you can use any way you like. As for whether it's a good idea, well, that part is up to you.

Here is a clickable Google search link with tool hints.

torek
  • 448,244
  • 59
  • 642
  • 775