Git head into string?


Is there a way to get the git head text in a string without blowing away the file in the current tab? Here is what I’m doing now but it is a real kludge and a bit dangerous …

  fileText = fs.readFileSync filePath
  gitRepo.checkoutHead filePath
  gitHeadText = fs.readFileSync filePath
  fs.writeFileSync filePath, fileText


What exactly do you mean by the “git head text”? Do you mean the text of the current file as exists at the HEAD revision in the Git repository? If so, can’t you just execute the git show command like so?

git show HEAD:foo.txt

And pipe the output of that into a string?





Thanks. Works great. I vote it goes into the API.


It’s weird but this worked when I first tried it and now it isn’t working. It returns null. I’m pretty sure my repo and file path are OK because this works …

atom.project.getRepo().isPathModified path

I’ll do some more research …

I’m on windows 8.0 and Atom 0.132.0


Hi Mark, were you ever able to get this to work? I am trying to use getHeadBlob() and it always returns null for me.