简体   繁体   中英

Git: What's the path separator used in the content of the .git\HEAD in Git repositories on Windows?

The title says it all, but for example, if the HEAD of a Git repository points to ref/heads/master on any well-used Git implementation for Windows, which of the following is the content of the file .git/HEAD ... oops, .git\HEAD :

  • ref: refs/heads/master , or
  • ref: refs\heads\master ?

Either way, I need to calculate the absolute path <git project>\.git\refs\heads\master , but I don't have Windows environment and I can't get to know which form is used. Answer is greatly appreciated.

Background: I'm modifying a Haskell library implementing a macro that embeds the Git revision hashes of Haskell projects into their source codes right on compilation (very nice for implementing --version option.), When we compile the program invocating that macro, git is called; however even before that, when a build tool is checking whether recompilation is required, we cannot call git and all that's done is simple file update check, Therefore, at the time of each compilation, we must compute and save the path of reference file at which HEAD is pointing, so that the reference file would be checked for update next time. The problem is that I would like to make the library cross-platform but that I don't know how to compute the path of a reference file on Windows, for I don't know the original form.

HEAD uses a reference name and not a path separator. Git always uses forward slashes in reference names, even on Windows. Backslashes are never allowed in a reference name on any platform, ever.

Since Windows will also allow forward slash path separators (unless you're using UNC paths), it's usually safe to just use forward slashes everywhere unless you know you have special needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM