当前路径对于某些 git 操作重要吗?

发布于 2024-12-09 02:26:01 字数 702 浏览 0 评论 0原文

假设我的 git 存储库(.git 文件夹)位于 ~/my_project/ 中。还假设我的项目文件夹是这样组装的:

my_project
      |
      |____src
            |
            |__com
            |
            |__org

最后,假设我想暂存 com 文件夹以进行提交。我至少可以通过两种方式做到这一点:

  • albus@hogwarts:~/my_project$ git add src/com
  • albus@hogwarts:~/my_project/src$ git add com

两次调用之间会有什么区别吗? git format-patchgit am 怎么样?它们取决于当前路径吗?

人们可能会嘲笑我的问题,但事实是,我的一位同事说他们在应用某些补丁时遇到了麻烦,即他们必须从项目路径中的不同目录应用它们。他们还建议我应该从最上面的项目文件夹(即本例中的 my_project)执行所有 git 命令。我从来没有想过这可能是真的,但我不是 git 相关的专家,因此我在这里问这个问题。

谢谢!

Say, I have my git repo (the .git folder) located in ~/my_project/. Assume also that my project's folder is assembled like that:

my_project
      |
      |____src
            |
            |__com
            |
            |__org

Last of all, assume that I'd like to stage the com folder for commit. I may do it in at least two ways:

  • albus@hogwarts:~/my_project$ git add src/com
  • albus@hogwarts:~/my_project/src$ git add com

Would there be any difference between the two invocations? What about git format-patch or git am? Do they depend on the current path?

People may laught at my question, but truth is, a colleague of mine said that they had trouble applying some patches, i.e. they had to apply them from different directories in the project path. They also recommended that I should do all git commands from the upmost project folder (i.e. my_project in this example). I never though there might be truth in this, but I'm not an expert where git comes into the picture and therefore I'm asking it here.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-12-16 02:26:01

无论您在何处运行命令,git format-patch都会创建相同的补丁。唯一改变的是补丁文件的生成位置。

但不同的命令的行为不同,这也取决于应用于它们的标志。

例如,git diff 具有 --relative 标志:

--relative[=<路径>]

当从项目的子目录运行时,可以告诉它排除目录外部的更改并显示相对于
就用这个选项。当您不在子目录中时(例如在
裸存储库),您可以指定要输出的子目录
相对于通过给出 a 作为参数。

git format-patch creates the same patch wherever you ran the command. Only thing that changes is where the patch file is generated.

But different commands behave differently, which also depends on flags applied to them.

For example, git diff has the --relative flag:

--relative[=<path>]

When run from a subdirectory of the project, it can be told to exclude changes outside the directory and show pathnames relative to
it with this option. When you are not in a subdirectory (e.g. in a
bare repository), you can name which subdirectory to make the output
relative to by giving a as an argument.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文