如果我有一个包含许多代码片段文件夹的文件夹,如何避免 Git 或 Mercurial 在另一个文件夹中提交源代码?
如果我有一个文件夹,例如:
code/try_closure
code/try_http_send
[...]
我可以在 code
文件夹中创建存储库,但如果我在 try_http_send
文件夹中提交:
hg commit -m "good version" <--- git should be similar
那么,我可能会意外提交其他代码code
下所有其他文件夹中的更改。
或者,我可以为每个子文件夹创建存储库,但这有点愚蠢,如果我需要将整个 code
推送到另一个位置,那么我需要逐个推送子文件夹一?有办法解决这个问题吗?这里的关键字是“意外”提交其他子文件夹中的所有文件。我知道我可以使用 hg commit 。 -m "good version",但是用 hg commit -m "..."
来代替就很容易了。
If I have a folder such as:
code/try_closure
code/try_http_send
[...]
I can create a repository at the code
folder, but then if I commit at the try_http_send
folder:
hg commit -m "good version" <--- git should be similar
then, I can accidentally commit other code changes in all other folders under code
.
Alternatively, I can create repositories for each of the sub-folders, but that's kind of silly and what if I need to push the whole code
to another location, then I need to push sub-folders one by one? Is there a way to solve this? The keyword here is "accidentally" commit all files in other sub-folders. I know I can use hg commit . -m "good version"
, but it is just so easy to do hg commit -m "..."
instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将它们设为单独的存储库,然后将它们设为顶级代码模块的子存储库。然后在代码中,您可以执行
hg push --subrepos
将它们全部推送,然后也可以克隆为树。Make them separate repositories and then make them subrepositories of a top level code module. Then within code you can do
hg push --subrepos
to push them all, and then can be clones as tree as well.存储库应该包含您想要一起提交的内容。如果您不想将不同文件夹中的代码一起提交,那么每个文件夹都应该是一个单独的存储库。
A repository should contain things that you want to commit together. If you never want to commit code from separate folders together, each folder should be a separate repository.
说真的,你应该把这段时间花在这段时间上。除此之外,检查下一次提交要做什么总是一个好主意,例如使用
hg st
和hg diff
。此类检查充当对要提交的工作的最后一次快速审查,并可能提醒您仅提交某些文件(例如.
)。除非您想截取当前工作的快照,否则不应盲目提交。也就是说,如果您确实想在没有文件参数的情况下提交,您可以
.
作为默认参数Seriously, you should spend that time for the period. Besides that, it's always a good idea to check what your next commit is going to do, e.g. by using
hg st
andhg diff
. Such a check acts as a last quick review for the work to commit and possibly reminds you to commit some files only (e.g..
). Unless you want to snapshot current work, you shouldn't commit blindly.That said, if you really want to commit without file arguments you could either
.
as a default argument