It's not uncommon to have the following structure of projects:
projectA - directory
projectB - directory
projectX - directory
CHANGELOG - file
LICENSE - file
README - file
This structure (the fact that README is located in the root directory) is supported well by different online Git solutions (like github.com, bitbucket.org).
How can we make Eclipse import CHANGELOG, LICENSE, README files from the root of repository and show them in Project Explored/Navigator?
(a similar question was asked Configure github to use some other file as README but its goal was to make online tool render a README from subdirectory. I'm insterested in the opposite: Eclipse showing the README, ...)
For README.md:
Right-click a project and choose New > File
In the New File dialog:
Click Advanced >>
Check Link to file in the file system
Enter PARENT-1-PROJECT_LOC/README.md
Click Finish
Note, these files are shown in the Git Repositories view below the Working Tree node. Instead of using the trick described above, just open these files via the Git Repositories and then edit, save and commit them as usual.
Related
I am looking to do something I thought was pretty simple... I have an existing folder (with project files) on my desktop that I would like have tracked by Github desktop for purposes of source/version control. It seems straightforward... I go to github desktop, select that I'd like to create a new repository, and point it at the folder on the desktop. Here is what I expect to happen:
Desktop
Project folder
Project files
(hidden) .git folder
(hidden) .gitattributes
Instead, this is what I get:
Desktop
Project folder
Project files
New folder with specified git repo name
(hidden) .git folder
(hidden) .gitattributes
I am not sure why this is happening and it is very frustrating. It looks to me like I have only two options here:
Cut and paste Project files into New folder with specified git repo name
Cut and paste .git folder and .gitattributes out of New folder with specified git repo name and into Project folder, delete New folder with specified git repo name, remove the new repo in Github Desktop when it says it can't find it, and "Add Existing repo" in Github Desktop and point it at Project folder.
Both of these approaches sort of feel like hacks and I am not sure what consequences, if any, may negatively impact my version control intention as a result. Is this a common problem? What should I do?
I wouldn't use github desktop to make your repository. If you don't have it already try installing git bash, a command line interface, and initialize git from there.
Find your existing folder and move to it using cd <folder name here> if you go into the wrong place use cd .. to move out/back one folder
When in your folder use git init to initialize git(the version control software)
Open GitHub Desktop once again and hit "add" then "add existing repository" finally "choose" and find your file in your file explorer
When you go to "Create a new repository":
Name: New folder with specified git repo name
Local Path: Desktop (ie one level up from Project files)
This will create the .git and .gitattributes in your existing folder without affecting the other files.
The Create a new repository dialogue seems to assume the name should be used as a new folder under the path you specify.
Note that if there are spaces in your name, it tries to replace them with hyphens.
Disclaimer: I'm new to EGit but familiar with command line Git.
In Eclipse Neon, I have a configured Git repository with this structure:
.git
README.md
.gitignore
projectA
.project
projectB
.project
projectC
.project
Problem: In Enterprise Explorer, Navigator, Project, and Package Explorer, I can only see ProjectA, ProjectB, and ProjectC, not README.md and .gitignore.
Question: How can I modify README.md and .gitignore from inside Eclipse?
Environment: Under Enterprise Explorer > Available Customizations, I have unchecked .*resources. Under Navigator > Filters I have unchecked .*
Package/Project Explorer, Navigator, etc. show only files of into Eclipse imported/opened projects. Files that are starting with . are hidden in the Package/Project Explorer, but are shown in the Navigator view by default.
In the Git Repositories view navigate to the file under the Working Tree node and double-click to open the file. Alternatively, use File > Open File....
Edit and save the file
In the Git Stagging view commit/push the file as usual
An alternative to what #howlger suggested is to create a project at the root of the repository working directory so that the readme and gitignore file become members of the workspace.
Create a General Project at the root of the working directory
Open the New Project wizard (File > New > Project) to create a General Project. Choose a project name of your choice, uncheck the Use default location checkbox, and enter the location of the repositories' working directory in the Location input field.
This will create a .project file with project metadata in the root of the working directory. If all team members use Eclipse as their IDE, it may make sense to commit this file to the repository.
(Optionally) use resource filters to exclude nested projects
Now, the Package Explorer and other navigation views show a project that contains all files and folders within the working directory, including folders that contain nested projects.
Resource filters can be used to exclude folders that contain nested projects so that only those files and folders appear that are not already shown within other projects.
To add a resource filter, open the Properties dialog of the root-level project and open the Resource > Resource Filters page. Often, all nested projects follow a common naming pattern. In this case a File and Folder Attributes filter that specifys a pattern to match the folder name can be used to exlude them. Otherwise, the Extras for Eclipse plug-ins offer a feature to exclude all Nested Wprkspace Projects.
Pros and Cons
Having all files in a repository within the IDE allows to easily edit and navigate through files including decorators that indicate the change status of all files.
Some users, however, may consider having an extra .project file at the root directory of the repository as a downside.
Because of how Eclipse and EGit organize files and directories, I have my README.md file not in the root directory of my git repository but one folder deeper. How can I tell github to show some_folder/README.md as project's readme?
In the root directory of your repo, create a folder named .github.
Create a file named README.md in this folder.
Save the relative path of the file you want to use as the repo README in .github/README.md.
This causes README.md to be interpreted as a symbolic link (symlink) file.
Example:
This repo has files named README.md and cmod-readme.md in its root directory. Normally the former would be used as the README shown on the repo's main page, but instead the latter is used.
The repo contains a .github/README.md file, which contains the relative path to cmod-readme.md, i.e., ../cmod-readme.md.
The fact that GitHub will follow symlinks when locating a repo's README doesn't seem to be documented, although the .github folder is mentioned on this page in GitHub's docs:
If you put your README file in your repository's root, docs, or hidden .github directory, GitHub will recognize and automatically surface your README to repository visitors.
It's also interesting that (based on the example repo linked above) GitHub apparently prioritizes the README.md file in .github over a file of the same name in the respository's root.
This seemed to do it for me:
https://stackoverflow.com/a/49981731/7452130
Github wouldn't interpret my .github/README.md file as a symlink unless I created a symlink on my system and then pushed it.
Current scenario :
In Eclipse when we create a project, say a PyDev project named ‘SimpleGit’, the folder structure created by eclipse will be like
EclipseWorkingDirectory/SimpleGit/src/
correct?
If we add this to git using Egit, by right clicking on the project folder SimpleGit then Team>Share, The folder structure in which repo is formed like this
Parent Folder/ SimpleGit/ .git
Parent Folder/ SimpleGit/SimpleGit/src/
And when we stage it to remote github everything will come under
Username/ SimpleGit / SimpleGit / src /
So when we look in GitHub in the root project folder (Username/ SimpleGit) we can’t see the source folder. It will be under another folder ‘SimpleGit’. How we can avoid this?
What I want is , I want to get my source forlder(src) listed under the Project Root directory, when staging from an already built project in eclipse using egit. How do I do this?
I want like this:
https://github.com/nicholasbishop/blender
Not like this:
https://github.com/afilash/SimpleGit
it cannot be done using eGit - it assumes the Eclipse project structure.
But it can be accomplished by using git itself. Just create a repository under SimpleGit folder executing 'git init'. From that point on you'd have to manage your git repository by either git itself (command line) or some other UI. SourceTree works really well for me.
It is a bit late, I know, but this method perfectly works and I hope it is useful for anyone who sees this post from now on.
The procedure is the following:
First step is creating a repository on Github (through github.com)
Move to Eclipse IDE (Git Repositories view) and click "Clone a Git Repository and add the clone to this view". Doing that the project will be somewhere located on the hard disk. Usually, it is stored in C:\Users\username\git\projectName but you are able to change it. This is our local repository.
Once done, press (in Eclipse IDE) File->Import->Projects from Git->Existing local repository(Select the one you cloned before)->Import using the new project wizard->Finish->Java->Java Project->Specify project name (just below the dialog box there is a checked checkbox that says use default location, uncheck it. Here is where you have to specify the directory you chose while cloning the repository previously).->Next->Finish
It should be enough for creating the right directory structure.
I'm trying to setup a git repository for my Eclipse project using EGit. However, I'm having trouble excluding the root/project directory from the repository. That being, my project has the structure:
ProjectDirectory
src
war
etc
I would like the repository to contain src, war, and etc, but not contain the parent directory ProjectDirectory. That's because if I want to clone a copy of the project in my workspace, ProjectDirectory2, the repository for the second project now will try to create a second root directory, ProjectDirectory. Unfortunately, when I try to add a repository for a project using EGit, I seem to only be able to use Team > Share Project on the project folder itself and I don't seem to see anyway to exclude the root directory in the repository from within Eclipse.
Any suggestions on how to skip the top directory in the repository using EGit? I'd prefer being able to do everything from within Eclipse, but if there isn't a way, is there a way to setup the repository this way outside of git, then still be able to use the git control regularly from within git on the repository skipping the top level directory? Thank you much.
Short answer is It is POSSIBLE with EGIT + M2E
trick is when doing share project -> in the configure git repo window
making sure use or create repository in parent folder of project is ticked
and making sure click create repository button
the main aim of this is to create the .git folder in you project root
not above your project root.
Here's my solution. Though not particularly elegant - the steps are all simple, it works, and can be done in about 10 minutes:
Clone the remote git repo into your local filesystem .. e.g.: ~/git/project_repo_root
Create your eclipse project as usual .. e.g.: ~/workspace/eclipse_project_root
Delete the project from eclipse (but not filesystem!)
Open file manager and move the eclipse project you just created from ~/workspace/ root into ~/git
mv ~/workspace/eclipse_project_root ~/git/
Move the .git/ folder from the repo folder to the eclipse project root folder:
mv ~/git/project_repo_root/.git ~/git/eclipse_project_root
Using a shell go into /eclipse_project_root/ and do the usual command line commands for all files you want in the repo:
git add <abc>; .. commit; .. push
Return to Eclipse and go to Git Perspective, and click "Add an existing local Git repo to this view". Select the git repo you are working with and the view should be updated with an entry for that repo once you say ok.
Once you see the local repo in your view, you can right click it and select Import Projects
Go back to your main development perspective (Java, etc) and you should see the project there with the Git markup on the root node in package explorer view.
~~~~~
At that point, you should see the eclipse project folder you had just moved (to ~/git in the examples described here)
I realize this is more verbose than I would like my answers to be, but for this particular challenge/solution .. I don't know of a more straightforward way to do it.
And as for the post above that describes you should always include the eclipse project root directory .. the reality is some projects/clients/etc require that the git repo not contain the root folder. So a solution like this is necessary sometimes
You should commit the project root for multiple reasons:
If you commit only sub directories of your project, you will miss files and folders which are hidden below the project root (e.g. the .settings directory and others). Those need to be committed also, otherwise your project is going to miss information and may not lead to the same results on another machine.
Your wish of trying to clone the same repository a second time in the same workspace sounds very much like you should re-read about git branches. In git, switching between branches is done after a blinking of the eye, so branches should be used when working on different features, versions or otherwise different editions of your project.
The Eclipse project name and the underlying folder name on disk do not need to be the same (watch out for the checkbox "use default location" when creating a new project). So you can checkout a second clone of the project with a different name.
If you later add more projects to your workspace (e.g. a test project), you cannot easily share them into the same git repository, as the content of those additional projects would mix up with the sub directories of the first project in the repository.
If you have maven project you would typical like to create a repository without the project folder created by egit. For my experience this is not possible with the egit plugin.
But it can be easily done from the git command line.
First move your existing eclipse/maven project from your eclipse workspace into your git folder (this is what also the egit plugin did):
mv myproject ~/git/
next create a new git repository
cd ~/git/myproject
git init
Now create a .gitignore file and place it into your new repository folder (~/git/myproject/.gitignore). This is an example for a .gitignore file:
# ignore all bin directories
# matches "bin" in any subfolder
bin/
# ignore all target directories
target/
# ignore all files ending with ~
*~
# ignore eclipse directories and project files
.settings/
.project
.classpath
Finally initalize your new repository with the content of your project
git add *
git commit -m "My initial commit message"
Thats it.
Now you can restart your eclipse and reimport the project from your new git repository.
Go into your eclipse egit repository view and coose 'import exisiting project'.