Git/Eclipse 工作流程
我使用 Eclipse 来编辑 Java,并使用 Git 作为我的 VCS。我应该将本地存储库放在工作区中还是工作区之外,并在每次要提交时复制文件?我知道我可以通过各种方式做到这一点,但我是 Git 新手,想知道哪种方式更好。
I use Eclipse to edit Java, and use Git for my VCS. Should I have my local repository in my workspace, or outside it, and copy the files every time I want to commit? I know I can do it every way, but I'm new to Git, and wondering which way is better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
目前的最佳实践是在工作空间之外创建 git 存储库。最常见的存储库形式包含几个具有某种逻辑结构的项目,而工作区则喜欢平面结构的项目。有关更多详细信息,请参阅EGit 用户指南/创建存储库时的注意事项。
当通过标准导入或 Egit 将项目导入工作区时,Eclipse 很乐意指向磁盘上的其他位置。
The best practice at the moment is to create your git repositories outside of your workspace. The most common form of repository contains a couple of projects in some logical structure, and the workspace likes projects in a flat structure. See the EGit User Guide/Considerations when creating Repos for more details.
When importing the projects into the workspace via standard import or EGit, Eclipse is happy to point to the other location on disk.
我的工作区中只有本地存储库。我不确定你为什么想将两者分开 - 为什么要为自己创造额外的工作?
编码、提交;代码,提交...(其中“代码”当然包括测试)
I just have the local repository in the workspace. I'm not sure why you'd want to keep the two separate - why create extra work for yourself?
Code, commit; code, commit... (where "code" includes tests of course)
里面。创建一个您必须记住将文件复制到其中的外部分支,等等,这开始消除使用 GIT 之类的 VCS 的一些原因:)
如果您想单独获取一些代码,您也可以随时创建和“签出”分支现在。然后分支代码和基本代码都在 VCS 中,您将始终能够管理它们以进行合并等。
Inside it. Creating an external one that you have to remember to copy files to, etc. starts to defeat some of the reasons to use a VCS like GIT :)
You can also always create and 'checkout' branches if you want to get some code separate for now. Then both the branch code and the base code are both in VCS and you'll always be able to mange them for merges, etc.
如果你习惯了颠覆,你可能首先会有这样的想法。但使用 Git 意味着将完整存储库作为您自己的工作区。
如果您不想将项目文件夹放在存储库中,您应该将 Eclipse 配置为使用 git 并将其添加到您的 .gitignore 文件中。
作为开发工作流程,我可以推荐 Vincent Driessen 博客中介绍的方法: http://nvie .com/posts/a-successful-git-branching-model/
If you are used to subversion you may have this thoughts first. But working with Git means to have the complete repository as your own workspace.
You should configure Eclipse to use git and add to your .gitignore file the project folder if you do not want to have it in the repository.
As development workflow I can recommend the method Vincent Driessen bloged about: http://nvie.com/posts/a-successful-git-branching-model/
您必须记住,Git 只是项目中的一个 .git 目录。因此,您可以在 Eclipse 工作区中只拥有一个可以使用的项目文件夹。如果您使用 Eclipse,我推荐 EGit 插件。
You have to remember that Git is just a single .git directory in your project. So you could just have one project folder that you work off of in your Eclipse workspace. If you are using Eclipse I recommend the EGit plugin.
在里面;特别是如果您的所有工作都在 Eclipse 中进行。在 Eclispe 之外管理存储库将更有可能在存储库中添加您不需要的文件(例如 war/WEB-INF/classes)。此外,从 Eclipse 进行管理意味着其他开发人员自然会更轻松地同步您的存储库并在 Eclipse 中设置他们的环境。
我想这个规则的一个很好的例外是,如果您正在维护某种开发环境文件夹(例如,使用 jdk/eclipse 安装使用的第三方库/jars 添加到构建路径/等)。因此,我想遵循的最佳一般规则是,如果您使用 Eclipse 来更改文件,那么您还应该使用 Eclipse 来管理 git 存储库中的文件。
另外,如果您还没有使用 EGit(我认为其他人已经提到过这一点)。
Inside it; especially if all of your work is in Eclipse. Managing the repo outside of Eclispe is going to make it much more likely to add files you don't want in your repo (ex war/WEB-INF/classes). Also, managing from Eclipse means it will naturally be easier for other developers to sync your repo and setup their environment in Eclipse.
I suppose a good exception to this rule would be if you were maintaining a dev-environment folder of some sort (ex, jdk used/eclipse install used/jars for 3rd party libraries to add to build path/etc). So I guess the best general rule to follow would be if you're using Eclipse to change the files, you should also be using Eclipse to manage the file in your git repo.
Also, use EGit if you aren't already (I think others have mentioned this).