当前路径对于某些 git 操作重要吗?
假设我的 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-patch
或 git 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论您在何处运行命令,
git format-patch
都会创建相同的补丁。唯一改变的是补丁文件的生成位置。但不同的命令的行为不同,这也取决于应用于它们的标志。
例如,
git diff
具有--relative
标志: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: