Does copying the Git bare repo change the log?

倾然丶 夕夏残阳落幕 提交于 2020-01-07 05:38:48

问题


I'd like to try out a few things with git and I don't want to screw anything up in the working repository.

To try to keep things safe, I've made a copy of the bare repo that I work from and from this repo I am intending to do all my pushes and tagging. I used:

cp --preseve -r original.git copy_of_original.git

Although I understand one can undo bad commits and whatnot, I don't want to leave the repo with all these reverted commits, nor do I want to do any refactoring, hence my desire to just work from a duplicate, bare repository.

The problem is, I execute the following:

git diff --name-only master@{"5 day ago"} master

and get back:

warning: Log for 'master' only goes back to Fri, 15 Feb 2013 20:42:43 -0500.

The original repo, which I don't want to touch, does indeed have files which were modified as of 5 days ago.

If I perform git log on my copied repo, the record of these 5 day old changes are all still there.

What is going on here?

Is there a better way to make an independent copy of the repository?

Update 1

I realized I was imprecise with my question. I had run:

git diff --name-only master@{"5 day ago"}

in the directory produced from:

git clone copy_of_original.git clone_of_copy

回答1:


The @{5 days ago} syntax relies on information from the reflog, as explained in the section of the git-rev-parse documentation quoted below. Reflogs are local to a repository, and never transferred by clone, fetch or push. This is not the information displayed by git log, unless the -g or --walk-reflogs option is used.

Bare repositories generally don't keep reflogs, so a copy of the repository wouldn't have that information either.

<refname>@{<date>}, e.g. master@{yesterday}, HEAD@{5 minutes ago}
    A ref followed by the suffix @ with a date specification enclosed in a brace pair
    (e.g.  {yesterday}, {1 month 2 weeks 3 days 1 hour 1 second ago} or {1979-02-26
    18:30:00}) specifies the value of the ref at a prior point in time. This suffix may
    only be used immediately following a ref name and the ref must have an existing log
    ($GIT_DIR/logs/<ref>). Note that this looks up the state of your local ref at a
    given time; e.g., what was in your local master branch last week. If you want to
    look at commits made during certain times, see --since and --until.



回答2:


If you clone, only part of the stuff is copied, if you copy, you have an identical version of the original repository. That works fine with git; can backup and restore, etc.




回答3:


Each clone includes a full copy of the repository (in the case where you have a single branch, master), inside the .git directory. Each copy independent of the others, and gets modified by local commits, or when you pull from an other repository.

So a recursive copy is perfectly fine.

As for what you see, you need to provide more details, and a more complete list of commands you run.



来源:https://stackoverflow.com/questions/14906091/does-copying-the-git-bare-repo-change-the-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!