4

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

1
  • 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. Commented Nov 15, 2010 at 0:11

2 Answers 2

3

Try to create a file within that folder, and add it.
For instance, an empty .gitignore file, which:

  • will be ignored by your web project
  • won't have any effect in the git repo

, 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:

  • creating a new git repo within that new directory (the one within your Web project)
  • referencing that new repo within your current git repo as a submodule, if you want to keep a tight link between the tow set of files.
Sign up to request clarification or add additional context in comments.

Comments

0

Say you want to track WebContent/MyFolder

  1. Rename MyFolder to something like MyFolder.tmp
  2. Create a new repository in WebContent with name MyFolder
  3. Copy the content of MyFolder.tmp into MyFolder
  4. Make a first commit of MyFolder
  5. Delete 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.