我有目录A,文件与目录B匹配.目录A可能有其他所需的文件.目录B是一个git仓库.
我想将目录B克隆到目录A但git-clone将不允许我,因为该目录是非空的.
我希望它只能克隆.git,因为所有的文件匹配,我可以从那里去?
我无法克隆到一个空目录,因为我在目录A中的文件不在目录B中,我想保留它们.
复制.git不是一个选项,因为我想要refs推/拉,我不想手动设置它们.
有没有办法做到这一点?
更新:我认为这有效,任何人都可以看到任何问题吗? - >
cd a
git clone --no-hardlinks --no-checkout ../b a.tmp
mv a.tmp/.git .
rm -rf a.tmp
git unstage # apparently git thinks all the files are deleted if you don't do this
Run Code Online (Sandbox Code Playgroud)
cmc*_*nty 675
这对我有用:
git init
git remote add origin PATH/TO/REPO
git fetch
git reset origin/master # Required when the versioned files existed in path before "git init" of this repo.
git checkout -t origin/master
Run Code Online (Sandbox Code Playgroud)
注意: -t
将为您设置上游分支,如果这是您想要的,通常是.
Dal*_*ter 153
在下面的shell命令中existing-dir
是一个目录,其内容与repo-to-clone
git存储库中的跟踪文件相匹配.
# Clone just the repository's .git folder (excluding files as they are already in
# `existing-dir`) into an empty temporary directory
git clone --no-checkout repo-to-clone existing-dir/existing-dir.tmp # might want --no-hardlinks for cloning local repo
# Move the .git folder to the directory with the files.
# This makes `existing-dir` a git repo.
mv existing-dir/existing-dir.tmp/.git existing-dir/
# Delete the temporary directory
rmdir existing-dir/existing-dir.tmp
cd existing-dir
# git thinks all files are deleted, this reverts the state of the repo to HEAD.
# WARNING: any local changes to the files will be lost.
git reset --hard HEAD
Run Code Online (Sandbox Code Playgroud)
moh*_*ied 96
稍微修改一个对我有用的答案:
git init
git remote add origin PATH/TO/REPO
git pull origin master
Run Code Online (Sandbox Code Playgroud)
立即开始在主分支上工作.
小智 25
这是我遇到同样问题时最终做的事情(至少我认为这是同样的问题).我进入目录A然后跑了git init
.
由于我不希望目录A中的文件后跟git,我编辑了.gitignore并将现有文件添加到其中.在此之后我跑了git remote add origin '<url>' && git pull origin master
etvoíla,B被"克隆"到A而没有一次打嗝.
Joh*_*nFF 23
git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master -f
Run Code Online (Sandbox Code Playgroud)
修改自@ cmcginty的答案 - 没有-f它对我不起作用
Mik*_*679 10
这对我有用:
cd existing_folder
git init
git remote add origin path_to_your_repo.git
git add .
git commit
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
另一个简单的配方似乎对我有用:
git clone --bare $URL .git
git config core.bare false
Run Code Online (Sandbox Code Playgroud)
检查带有现有文件的目录的主要用例是使用Git控制我的Unix dotfiles.在一个新帐户上,主目录中已经有一些文件,甚至可能是我想从Git获取的文件.
小智 8
我刚刚使用过这个,需要最少的潜在破坏性命令:
cd existing-dir
git clone --bare repo-to-clone .git
git config --unset core.bare
git reset
Run Code Online (Sandbox Code Playgroud)
瞧!
我在计划用作临时 Web 服务器的新 Apache Web 目录(使用 WHM 创建的帐户)时遇到了类似的问题。我需要最初使用那里的代码库克隆我的新项目,并通过从存储库中提取来定期部署更改。
问题是该帐户已经包含 Web 服务器文件,例如:
.bash_history
.bash_logout
.bash_profile
.bashrc
.contactemail
.cpanel/
...
Run Code Online (Sandbox Code Playgroud)
...我不想删除或提交到我的存储库。我需要他们只是呆在那里,不上演和不跟踪。
我做了什么:
我去了我的网络文件夹(existing_folder):
cd /home/existing_folder
Run Code Online (Sandbox Code Playgroud)
进而:
git init
git remote add origin PATH/TO/REPO
git pull origin master
git status
Run Code Online (Sandbox Code Playgroud)
它显示(如预期)许多未暂存文件的列表 - 那些最初已经存在于我的 cPanel 网络帐户中的文件。
然后,多亏了这篇文章,我才将这些文件的列表添加到:
**.git/info/exclude**
Run Code Online (Sandbox Code Playgroud)
该文件几乎与该.gitignore
文件一样,允许您忽略暂存的文件。在此之后,我在 .git/ 目录中没有任何内容可提交 - 它就像.gitignore
一个其他人无法看到的个人。
现在检查git status
返回:
On branch master
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
现在我可以通过简单地从我的 git 存储库中拉取更改来部署对这个 Web 服务器的更改。希望这有助于一些 Web 开发人员轻松创建临时服务器。
也许我误解了您的问题,但是如果您将文件从 A 复制/移动到 git repo B 并使用git add 添加所需的文件,会不会更简单?
更新:来自 git 文档:
仅当目录为空时才允许克隆到现有目录。
来源:http : //git-scm.com/docs/git-clone
这是我在做什么:
git clone repo /tmp/folder
cp -rf /tmp/folder/.git /dest/folder/
cd /dest/folder
git checkout -f master
Run Code Online (Sandbox Code Playgroud)
以下对我有用。首先,我会确保目录中的a
文件是受源代码控制的:
$ cd a
$ git init
$ git add .
$ git commit -m "..."
Run Code Online (Sandbox Code Playgroud)
然后
$ git remote add origin https://URL/TO/REPO
$ git pull origin master --allow-unrelated-histories
$ git push origin master
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
271059 次 |
最近记录: |