简体   繁体   English

Git 责备查看所有提交历史

[英]Git blame see all history of commit

We have a Git repo in which we all made deliveries and track details.我们有一个 Git 存储库,我们都在其中进行了交付和跟踪详细信息。

One of the other teams in our organization has another project to re-organize the code in our repo and they made some changes in file location [no code] / created new library etc and created a new repo.我们组织中的其他团队之一有另一个项目来重新组织我们仓库中的代码,他们对文件位置进行了一些更改[无代码]/创建了新库等并创建了一个新仓库。

Now doing a git blame refers me to one who migrated the code not who has written the code?现在做一个 git 责备我指的是迁移代码的人而不是编写代码的人?

How can I get the actual author of the code via blame now?我现在如何通过责备获得代码的实际作者?

What I understand is someone copied the files to a new repo and lost their history.我的理解是有人将文件复制到新的仓库并丢失了他们的历史记录。

It should not have been necessary to copy the files to a new repo in the first place.首先应该没有必要将文件复制到新的存储库。 The reorganization should have happened as a normal commit.重组应该作为正常提交发生。 Then tools such as git log and git blame would be able to continue to track the history of the files across renames and copies.然后,诸如git loggit blame之类的工具将能够继续跨重命名和副本跟踪文件的历史记录。 The only reason I can think you would need a new repository is if the history got bloated with large files like videos, images, and office documents.我认为您需要一个新存储库的唯一原因是历史记录是否因视频、图像和办公文档等大文件而变得臃肿。 That is better solved using git-lfs retroactively . 追溯使用 git-lfs可以更好地解决这个问题。

Now that you're in this situation, the best thing to do is to rewrite the new repository on top of the old one.既然您处于这种情况,最好的办法是在旧存储库之上重写新存储库。 Let's say your old and new repos look like this.假设您的旧回购和新回购看起来像这样。

old
A - B - C - D [master]

origin
X - Y - Z [master]

local
X - Y - Z [origin/master]
          [master]

"origin" is the new repository you cloned from. “origin”是您从中克隆的新存储库。 "local" is your clone. “本地”是您的克隆。

You want to stitch them together like this.你想像这样把它们缝合在一起。

old
A - B - C - D [master]

origin
A - B - C - D - X1 - Y1 - Z1 [master]

new
A - B - C - D - X1 - Y1 - Z1 [origin/master]
                             [master]

First, make the old repository a remote of the new one and fetch it.首先,使旧存储库成为新存储库的远程并获取它。

$ cd new
$ git remote add old <url to old repo>
$ git fetch old

old
A - B - C - D [master]

origin
X - Y - Z [master]

local
A - B - C - D [old/master]

X - Y - Z [origin/master]
          [master]

Now your new repository has the old history of master available as origin/master.现在,您的新存储库具有 master 的旧历史记录,可用作 origin/master。

Then rebase the new commits on top of the old commits.然后在旧提交之上重新定义新提交。

$ git checkout master
$ git rebase old/master

old
A - B - C - D [master]

origin
X - Y - Z [master]

local
A - B - C - D [old/master]
             \
              X1 - Y1 - Z1 [master]

X - Y - Z [origin/master]

Now it's time to push your changes.现在是时候推动你的改变了。 Your local master and remote master have "diverged", your local changes are no longer simply on top of the remote ones.您的本地主机和远程主机已经“分歧”,您的本地更改不再只是在远程更改之上。 You will need to force the push.您将需要强制推动。 Use git push --force-with-lease to safely force the push .使用git push --force-with-lease安全地强制 push

$ git push --force-with-lease

old
A - B - C - D [master]

origin
A - B - C - D - X1 - Y1 - Z1 [master]

local
A - B - C - D [old/master]
             \
              X1 - Y1 - Z1 [origin/master]
                           [master]

Remove old as a remote.删除旧的作为遥控器。

$ git remote rm old

old
A - B - C - D [master]

origin
A - B - C - D - X1 - Y1 - Z1 [master]

local
A - B - C - D - X1 - Y1 - Z1 [origin/master]
                             [master]

Others who have cloned the new repository and done work should git pull --rebase to update their master branch.其他克隆了新存储库并完成工作的人应该git pull --rebase更新他们的主分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM