简体   繁体   中英

git still showing diffs with a remotely (and locally) deleted branch

Basically I'm used to git fetch an then : git diff remotes/origin/my_branch_to_compare_with

But now I did a git fetch and then git diff remotes/origin/the_remote_branch_I_want_to_compare_with : git is still showing some diffs... How is that possible ? I guess it store information about the remotely deleted branch ? The remote branch was deleted from gitlab.

If there is a branch on the remote, and you clone the remote and locally check out the branch, there are now (at least) three refs related to the branch.

1) The branch in the remote

2) The branch in the local repo

3) A "remote tracking ref" in the local repo; sometimes called a "remote tracking branch", but be aware it is not a branch

As you may know, the remote tracking ref is updated when you fetch so that the local ref

origin/some-branch

tells you where the remote repo's branch

some-branch

pointed as of that fetch. What you may not know is that by default, when a branch is deleted from the remote, fetching does not automatically delete the corresponding remote tracking ref.

If you want the local to delete the remote tracking ref, you can say

git fetch --prune

But until you either do that, or manually delete the remote tracking ref from the local repo, the local will remember where the remote's branch pointed the last time a fetch reported that the branch existed.

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