0

I'm trying to copy the commit history (git log) from one repo to another. I have found another topic that asked a similar question. The solution was to run:

git log --pretty=email --patch-with-stat --reverse -- path/to/file_or_folder | (cd /path/to/new_repository && git am)

I have run it, and it looks like it works (the log history the same). But this change is only local. How can I do it to remote also? I can't use git add and then git commit because I don't have anything to commit. How can I change the history of the new repo to be the same as the old repo (they both contain the same files without changes).

vesii
  • 2,760
  • 4
  • 25
  • 71
  • 2
    You might be interested in the Git book on [working with remotes](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) since this can be done entirely by connecting the two repositories and fetching and merging them. – poke Nov 11 '19 at 10:20
  • I'm familiar with the book and the commands. I'm just afraid to make some stupid mistake that I can't revert. I have the two repos locally. How can I merge them so the first one will stay as it and the second one will have all the log history? – vesii Nov 11 '19 at 11:57
  • 1
    If you want the other to be the same as the former, then you could just throw away the second and make a fresh clone. – poke Nov 11 '19 at 12:16
  • Commit history *is* commits. Just fetch the commits. In the target repository, you will need some sort of name—a branch name, or a tag name, or something like that—to remember the *last* commit, from which you can find all of the earlier commits. The `git fetch` command sets such a name for you, called a *remote-tracking* name. – torek Nov 11 '19 at 17:01
  • If you intend to send the commits in the other direction—from your Git to theirs—you have two choices: have them `git fetch` from you, or use `git push`, which is as close as there is to the opposite of `git fetch`. The advantage and drawback of `git push` is that `git push` needs to set one of *their* names in *their* repository: as the one doing the `git push`, you select which name you'll ask them to set. There is no such thing as a remote-tracking name in this case. – torek Nov 11 '19 at 17:03

0 Answers0