1

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!

2
  • 1
    Well, I just checked format-patch (you can do that to, thanks to git being decentralized, you can create repo anytime anywhere). It gives the same output no matter what directory you are in, files are identical.
    – dmedvinsky
    Oct 9, 2011 at 19:55
  • Yep, you're right, I could try it myself, but expert's knowledge is always worth hearing. Oct 9, 2011 at 19:57

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.