将文件夹从 Eclipse 项目添加到 Git 源代码管理
我的本地工作区中有一个 Eclipse 动态 Web 项目设置。我想将项目的一个文件夹置于 Git 源代码管理之下。这可能吗?
我不需要存储库中的整个项目,只需要 WebContent
中的特定文件夹。我有 EGit 插件并从 Eclipse 中创建了一个新的 Git 存储库,但不知道如何将文件夹添加到存储库(存储库和文件夹当前位于不同的位置)。
谢谢
I have an Eclipse Dynamic Web Project setup located in my local workspace. I want to place one of the folders of the project under Git source control. Is this possible?
I don't want the entire project in the repository, just a specific folder within WebContent
. I have the EGit plugin and created a new Git repo from within Eclipse, but do not know how to add the folder to the repository (the repository and the folder are currently in different locations).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在该文件夹中创建一个文件,然后添加它。
例如,一个空的
.gitignore
文件,该文件:,但将允许 Git 树包含其父目录(即您要添加的目录)
正如 Jefromi 在评论中指出的那样:
“给定目录中的 git 存储库只能跟踪该目录中的内容没有办法解决这个问题。
您需要将存储库移动到包含您的文件夹,或者将文件夹移动到存储库中。 “
这意味着,如果您已经拥有给定工作树的 Git 存储库,并且想要添加位于其他位置的目录的内容,我建议:
Try to create a file within that folder, and add it.
For instance, an empty
.gitignore
file, which:, but will allow for the Git tree to include its parent directory (i.e. the directory you want to add)
As Jefromi points out in the comment:
"A git repository in a given directory can only track content within that directory. There's no way around this.
You need to either move the repository to contain your folder, or your folder to within the repository. "
Meaning if you already have a Git repo for a given working tree, and want to add the content of a directory located elsewhere, I would recommend:
假设您想要跟踪
WebContent/MyFolder
MyFolder
重命名为MyFolder.tmp
WebContent
中创建一个新存储库使用名称MyFolder
MyFolder.tmp
的内容复制到MyFolder
MyFolder
MyFolder.tmp
但是,我不建议仅将 Eclipse 项目的一部分放入源代码管理中。此外,存储库位置是工作区文件夹中的绝对路径。
Say you want to track
WebContent/MyFolder
MyFolder
to something likeMyFolder.tmp
WebContent
with nameMyFolder
MyFolder.tmp
intoMyFolder
MyFolder
MyFolder.tmp
However, I do not recommend putting just parts of an Eclipse project into source control. Also, the repository location is an absolute path in your workspace folder.