[英]Git pull into existing project without git folder
This seems like it should be a common issue, but perhaps I'm not searching for the correct terminology. 这似乎应该是一个常见问题,但是也许我不是在寻找正确的术语。
I just copied an old project on a remote server to my local machine using scp
. 我只是使用
scp
将远程服务器上的旧项目复制到本地计算机上。 I created a new instance of a git repository using git init
and used git remote add origin ...
to create a new remote git repository on-line, which I pushed to. 我使用
git init
创建了一个git存储库的新实例,并使用git remote add origin ...
创建了一个新的远程git存储库,并将其推送到了。 This is the projects first instance of being tracked by git. 这是git跟踪的项目的第一个实例。
I created a .gitignore file so not all the content was pushed to the remote repository and I also pushed some minor changes after the initial commit. 我创建了一个.gitignore文件,因此并非所有内容都被推送到远程存储库,并且在初始提交之后我还推送了一些小的更改。
Now I wish to pull the repository to the original project on the remote server. 现在,我希望将存储库拉到远程服务器上的原始项目。 It obviously has no .git folder.
它显然没有.git文件夹。 I want the changes to be pulled but keep the files listed in the .gitignore, so I can't simply wipe the directory and perform a clean
git clone
. 我希望撤消更改,但将文件保留在.gitignore中,因此我不能简单地擦除目录并执行干净的
git clone
。
I only have ssh access. 我只有SSH存取权。 How do I go about this?
我该怎么办?
Ok figured out a method that worked for me using ssh. Ok找出了一种使用ssh对我有用的方法。
Copy the local projects .git folder to the project on the remote servers directory. 将本地项目.git文件夹复制到远程服务器目录上的项目。 You may have to copy to a folder with correct privileges then move the .git folder
您可能必须复制到具有正确权限的文件夹,然后移动.git文件夹
scp /local/path/to/.git user@remote:/remote/path/to/temp/folder
Change the ownership of the .git and move it to the existing projects directory 更改.git的所有权并将其移至现有项目目录
chown -R www-data:www-data .git/
mv .git/ /var/www/....
Performing a git status shows the changed files and untracked files. 执行git status显示更改的文件和未跟踪的文件。 In my case the 'changed' files were the old files I wanted to overwrite, and the untracked files where the files I specified in .gitignore.
就我而言,“已更改”文件是我想覆盖的旧文件,而未跟踪文件是我在.gitignore中指定的文件所在的位置。
So to 'revert' the files to the new versions in the branch (stored in the .git folder) and ignore the untracked files, I just did 因此,要将文件“还原”到分支中的新版本(存储在.git文件夹中)并忽略未跟踪的文件,我只是做了
git checkout .
This also added the .gitignore file, which I had to chown
too. 这也添加了.gitignore文件,我也不得不对其进行了
chown
。
This was tested on a project with only a master branch, but I hope this helps people in the future. 这在只有主分支的项目上进行了测试,但是我希望这对以后的人们有所帮助。 My terminology may be a little off describing the git processes but hopefully everyone gets the picture.
我的术语可能不太适合描述git的过程,但希望每个人都能理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.