简体   繁体   中英

Git blame see all history of commit

We have a Git repo in which we all made deliveries and track details.

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?

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. 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 .

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. "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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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