Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何开始重新跟踪git存储库?_Git - Fatal编程技术网

如何开始重新跟踪git存储库?

如何开始重新跟踪git存储库?,git,Git,我在Github上有一个git存储库。我在远程服务器上有相同的存储库,具有相同的文件结构。事情发生了,我的远程服务器上的.git目录被删除 是否有一种方法可以将远程服务器上的存储库更改为再次跟踪Github上的存储库,并将Github上的存储库设置为origin完成后,我希望远程服务器上的存储库的行为与Github上的存储库的行为完全相同 我无法从远程服务器删除存储库并再次从Github克隆它。是,在远程服务器上使用: git remote set-url origin <your git

我在Github上有一个git存储库。我在远程服务器上有相同的存储库,具有相同的文件结构。事情发生了,我的远程服务器上的
.git
目录被删除

是否有一种方法可以将远程服务器上的存储库更改为再次跟踪Github上的存储库,并将Github上的存储库设置为
origin
完成后,我希望远程服务器上的存储库的行为与Github上的存储库的行为完全相同


我无法从远程服务器删除存储库并再次从Github克隆它。

是,在远程服务器上使用:

git remote set-url origin <your github remote url>
git远程设置url源
您可以执行以下操作:

git init
git remote add origin <remote-url>
git pull
git init
git远程添加源
吉特拉力
  • 开始。git
    文件夹被删除,
    git init
    将在远程服务器中再次初始化git repo
  • 添加
    origin
    将有助于您使用github中的回购跟踪本地回购
  • 添加
    origin
    后,将从github中提取更改
    我就是这样做到的。它涉及到在远程服务器上创建一个临时的
    master
    分支,然后用
    origin/master

    git init
    git remote add origin <url/to/origin>
    git fetch -a
    
    git branch -m master temp-master # Rename the just created master
    git branch --track master origin/master # Track origin/master in master
    
    git checkout master
    git branch -d temp-master # You might need to use -D
    
    您可能不想将所有文件转移到提交,而是让它们不受跟踪。使用
    git reset--
    取消这些文件或目录的存储

    git status # Check the files that you're going to commit.
    git commit # Create a temporary master branch for now.
    
    现在重命名主分支,并创建另一个跟踪原点/主分支的
    master

    git init
    git remote add origin <url/to/origin>
    git fetch -a
    
    git branch -m master temp-master # Rename the just created master
    git branch --track master origin/master # Track origin/master in master
    
    git checkout master
    git branch -d temp-master # You might need to use -D
    
    现在卸下
    temp master

    git init
    git remote add origin <url/to/origin>
    git fetch -a
    
    git branch -m master temp-master # Rename the just created master
    git branch --track master origin/master # Track origin/master in master
    
    git checkout master
    git branch -d temp-master # You might need to use -D
    
    检查一切是否正确

    git log
    

    由于.git文件夹已被删除,“git init”将初始化git repo,然后可以发出第二个命令来跟踪原始版本,但我不明白这一点。我知道他跟踪的远程回购被删除了.git文件夹。我删除了我的评论,更新了我的问题。我希望远程服务器上的repo的行为类似于Github repo的克隆。这个答案中的命令将简单地添加一个
    remote
    ,带有指向Github的源名称。如何从Github中提取更改和分支信息?添加“remote”后,执行“git pull”。这将把更改从github拉到远程服务器中的repo。也许您可以编辑您的答案,将您给出的解释包含在注释中