简体   繁体   English

如何组织本地 Git 存储库

[英]How to Organize Local Git Repo

I am new to git and having a hard time keeping this organized.我是 git 的新手,很难保持井井有条。 The way it's organized at present is I have created one repo and under this I have different sub projects.它目前的组织方式是我创建了一个 repo,在此之下我有不同的子项目。 inside this projects I have code and docs as well(which I dont commit to remote but needed).在这个项目中,我也有代码和文档(我不承诺远程但需要)。 The docs changes I dont want to track but i expect them to come when I create branch.我不想跟踪文档更改,但我希望它们在我创建分支时出现。 If i make changes in them when I am inside a branch and then I change back the branch, i want to see them updated in other branches well.如果我在分支中对它们进行更改,然后又将分支改回,我希望看到它们在其他分支中得到很好的更新。 currently I just add them in "exclude" file in .git repo.目前我只是将它们添加到 .git repo 的“排除”文件中。 is it the correct way?这是正确的方法吗?

Having one git repo with multiple projects inside it might be difficult to manage in the future.拥有一个包含多个项目的 git 存储库,将来可能难以管理。

  • Commits might get you mixed-up, which change for which project is.提交可能会让你混淆,哪个项目是哪个更改。
  • Keeping track of your history might get messy quickly.跟踪您的历史记录可能很快就会变得一团糟。
  • You might find it hard to change the history of one project without affecting the rest.您可能会发现很难在不影响其余项目的情况下更改一个项目的历史记录。

You can have one git repo with multiple git repos inside - this would be using git submodules .可以有一个里面有多个 git repos 的 git repo - 这将使用git submodules

But maybe what you want, and what would be better to manage is to have for each project a separate git repo.但也许您想要什么,并且更好地管理是为每个项目拥有一个单独的 git 存储库。 That way each project would be encapsulated on its own and you wold find it easier to keep track of the different projects.这样每个项目都会被单独封装,你会发现跟踪不同的项目会更容易。

Of course, if you think that you don't need that, then you don't have to make so many git projects and you can stick with your current setup.当然,如果你认为你不需要那个,那么你就不必做这么多的 git 项目,你可以坚持你当前的设置。

If you don't want to track changes for a certain document or for a directory, then you can use a gitignore file .如果您不想跟踪某个文档或目录的更改,则可以使用gitignore 文件 With this, you specify which documents you don't want to track.有了这个,你指定哪些文件你不想跟踪。

If i make changes in them when I am inside a branch and then I change back the branch, i want to see them updated in other branches well.如果我在分支中对它们进行更改,然后又将分支改回,我希望看到它们在其他分支中得到很好的更新。

Well if you change branches in your repo (or repos depending on which approach you decide to take), your changes will be only to that branch and the rest of your branches won't see those changes (unless you merge the branches).好吧,如果您更改仓库中的分支(或取决于您决定采用哪种方法的仓库),您的更改将仅针对该分支,而您的其余分支将不会看到这些更改(除非您合并分支)。

And don't forget, there are many resources on the internet that can help you find the best way to organize each of your projects, with its own structure and everything!并且不要忘记,互联网上有很多资源可以帮助您找到组织每个项目的最佳方式,它们都有自己的结构和一切!

I understand your affliction, I also wanted to have local changes always there when I am reviewing a project.我理解您的痛苦,我也希望在审查项目时始终进行本地更改。 But I don't want to commit my changes, why?但是我不想提交我的更改,为什么? Because it's not ready, or I'm not sure I am going to stick with it or whatever I decide to do.因为它还没有准备好,或者我不确定我是否会坚持下去或我决定做的任何事情。

So I end up with a several changes, mostly from the project I'm working on, and some from my "permanent" local changes.所以我最终进行了一些更改,主要来自我正在处理的项目,还有一些来自我的“永久性”本地更改。 And I have to be careful not to pick the wrong file when staging the changes.而且我必须小心不要在暂存更改时选择错误的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM