我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。


当前回答

要补充其他答案:如果远程因某种原因已被更改,因此不反映原来的起源,则重组中的第一个输入(即由命令 git reflog 显示的最后一个输入)应指明重组原来的位置。

吉。

$ git reflog | tail -n 1
f34be46 HEAD@{0}: clone: from https://github.com/git/git
$

(请记住,返回可以被清理,所以这不保证工作。

其他回答

我认为你可以找到它在.git/config 和远程[“起源”] 如果你没有操纵它。

我基本上使用:

git remote get-url origin

在 Windows 中,它适用于 Git Bash 命令控制台或 CMD 命令控制台。

#!/bin/bash

git-remote-url() {
 local rmt=$1; shift || { printf "Usage: git-remote-url [REMOTE]\n" >&2; return 1; }
 local url

 if ! git config --get remote.${rmt}.url &>/dev/null; then
  printf "%s\n" "Error: not a valid remote name" && return 1
  # Verify remote using 'git remote -v' command
 fi

 url=`git config --get remote.${rmt}.url`

 # Parse remote if local clone used SSH checkout
 [[ "$url" == git@* ]] \
 && { url="https://github.com/${url##*:}" >&2; }; \
 { url="${url%%.git}" >&2; };

 printf "%s\n" "$url"
}

使用:

# Either launch a new terminal and copy `git-remote-url` into the current shell process, 
# or create a shell script and add it to the PATH to enable command invocation with bash.

# Create a local clone of your repo with SSH, or HTTPS
git clone git@github.com:your-username/your-repository.git
cd your-repository

git-remote-url origin

出口:

https://github.com/your-username/your-repository

上流的远程可能不会被称为“起源”,所以这里有一个变量:

remote=$(git config --get branch.master.remote)
url=$(git config --get remote.$remote.url)
basename=$(basename "$url" .git)
echo $basename

或:

basename $(git config --get remote.$(git config --get branch.master.remote).url) .git

对于更有用的变量,有:

$ git config -l

Git URL 将位于 Git 配置文件中,值相当于关键 URL。

对于 Mac 和 Linux,请使用下面的命令:

cd project_dir
cat .git/config | grep url | awk '{print $3}'

在 Windows 中,在任何文本编辑器中打开下面的文件,并找到关键URL的值。

project_dir/.git/config

注意: 即使您离线或远程 Git 服务器已被删除,这也将工作。