git查看下载的远程源
151 2025-10-22 14:04
在 Git 中,你可以通过以下命令查看当前仓库的远程源(即下载来源):
bash
复制
git remote -v
这个命令会列出所有远程仓库的名称及其对应的 URL,通常你会看到类似这样的输出:
复制
origin https://github.com/username/repo.git (fetch)
origin https://github.com/username/repo.git (push)
其中:
-
origin是默认的远程仓库名称; -
第一行是用于 fetch(拉取) 的地址;
-
第二行是用于 push(推送) 的地址。
如果你用的是 GitHub、Gitee 等镜像源
有时候国内用户会使用镜像源(比如清华、中科大、Gitee 等),你可以通过
git remote -v 查看是否指向了这些镜像地址。示例:查看并确认源
bash
复制
$ git remote -v
origin https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git (push)
这说明你是从清华镜像下载的 Linux 内核源码。
小提示
如果你克隆的是 GitHub 仓库,但用的是镜像地址,提交代码时可能需要改回 GitHub 地址才能正常 push:
bash
复制
git remote set-url origin https://github.com/username/repo.git
在 Git 中,要查询当前 commit 的哈希值(即当前 HEAD 指向的 commit 的完整 SHA-1 哈希),你可以使用以下命令:
bash
复制
git rev-parse HEAD
这个命令会输出当前分支最新提交的完整哈希值,例如:
a1b2c3d4e5f6...(40 位十六进制字符串)
补充说明:
-
如果你只想要前 7 位(常用于简短引用):bash
-
复制
git rev-parse --short HEAD -
如果你想查看当前提交的哈希和提交信息:bash
-
复制
git log -1 --oneline
如有其他 Git 相关问题,欢迎继续提问。
全部评论