git bug 或误用分支?
我有一个大型项目,正在升级到 Edge Rails。我制作了整个项目目录的副本并在那里进行了重构,作为信任 git 的预防措施(或者至少是我可能如何使用/误用它)。完成大部分工作后,我返回到原始项目目录和控制台(这是来自记忆,因此大致基于实际发生的情况):
git branch edge
git checkout edge
git rm vendor/plugins
git commit -m "wiped out old plugins"
然后我手动复制了我在我的插件中更新的最新版本的插件复制的项目。
git add vendor/plugins
git commit -m "re-added in plugins, some unchanged, some later versions"
我的理解是上面的add是递归的。为了获得对 git 的信任,我在工作期间多次在主分支和边缘分支之间来回交换,只是为了确保它可以正常处理交换。
git checkout master
git checkout edge
我注意到(经过一些交换后)边缘分支中的一些插件恢复到了主版本。我多次尝试提交有问题的插件的最新版本,但它最终在交换后恢复。
我怀疑手动移动文件后添加文件的方式可能存在问题。 ( git addvendor/plugins/* 是必要的吗?)当两个分支包含一些相同的子目录时,有人在分支之间交换时遇到任何问题吗?您如何处理将一个目录中的应用程序副本中发现的更改合并回原始目录?原始存储库是干净的,而副本由于试图让某些插件在边缘分支中保持更改而相当混乱。
I have a large project that I was upgrading to edge Rails. I made a copy of the entire project directory and refactored there as a precaution to trusting git (or at least how I might use/misuse it). After completing most of the work I returned to the original project directory and at the console (this is from memory and so is loosely based on what actually happened):
git branch edge
git checkout edge
git rm vendor/plugins
git commit -m "wiped out old plugins"
then I manually copied in the latest versions of the plugins which I had updated in my copied project.
git add vendor/plugins
git commit -m "re-added in plugins, some unchanged, some later versions"
My understanding is that the above add is recursive. To gain some trust in git I swapped back and forth between the master branch and the edge branch at various times during my work, just to make sure it was handling swapping okay.
git checkout master
git checkout edge
What I noticed is that (after some swaps) in the edge branch some of the plugins reverted to the master versions. Numerous times I attempted to commit the lastest version of the problematic plugin, but it eventually reverted after swapping.
I suspect that there might have been an issue with the way I added the files after manually moving them over. (Was git add vendor/plugins/* necessary?) Has anyone had any issue with swapping between branches when two branches contain some of the same subdirectories? How might you handle the merging of the changes found in a copy of the app found in one directory back into the original? The original respository is clean, whereas the copy is fairly messed up from having attempted to get certain plugins to remain changed in the edge branch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是一种非常奇怪的方式来实现你的意图。
执行您提议的更多“git”方式是:
从那里开始,根据您的目标,您可以:
或者维护两个分支。一个移植到边缘,另一个未移植。这可能不是您想要的。 git 中的分支既便宜又简单,并且在完成后将它们扔掉是完全可以接受的。
That seems like a really strange way to do what you intended.
The more "git" way of doing what you proposed would have been to:
From there depending on what you're goal is you can:
Or maintain two branches. One ported to edge, the other the unported. This is probably not what you want. Branches in git are cheap and easy and is perfectly acceptable to throw them away when you are done.
git checkout
不会删除不在提交中的文件。您必须使用 git clean -f 删除当前工作目录中所有不需要的文件。您也可以删除该文件夹并再次使用 git checkout -f 。除此之外,最好创建一个分支来处理您的边缘功能,然后将分支合并回去,就像杰里米·沃尔提到的那样
git checkout
will not remove files not in a commit. you have to usegit clean -f
to remove all unwanted files in the current working directory. you could also just remove the folder andgit checkout -f
again.other than that it’s really better to create a branch for working on your edge features and then merge the branch back, like mentioned by jeremy wall