In a ruling made public on Thursday, U.S. District Judge David Carter in Santa Ana, California said the McGraw Hill Financial Inc unit may force Geithner to turn over unedited versions of the documents.

S&P believes the documents may support its claim that the February 2013 lawsuit was filed in retaliation for its having downgrading the country's debt 18 months earlier.

Carter reviewed the documents before ruling and said the government will have a chance to invoke White House privilege before Geithner must turn them over to S&P.

"A former executive official cannot, with one hand, withhold information implicated in a case of significant public importance while, with the other, collect money from sales of a tell-all book containing much the same information," Carter wrote. "The public has a right to every man's evidence."

Carter also reviewed dozens of unredacted documents that S&P had sought from the government. He ordered that all but five be turned over to S&P, saying the rating agency had demonstrated a "compelling" or "substantial" to obtain them for its defense.

Geithner's book "Stress Test: Reflections on Financial Crises" spent the month of June on the New York Times' hardcover nonfiction best-seller list, ranking fourth in its first week.

Jenni LeCompte, a spokeswoman for Geithner, declined to comment. Geithner is now president at Warburg Pincus LLC. A spokesman for the private equity firm did not immediately respond to a request for comment. The U.S. Department of Justice had no immediate comment.

"We're pleased that the court is making available to us additional materials," S&P spokesman Edward Sweeney said.

The lawsuit accused S&P of inflating ratings to win more fees from issuers and then failing to downgrade debt backed by deteriorating mortgage-backed securities fast enough.

Carter's decision is dated Sept. 24.

In seeking to keep S&P from seeing Geithner's book notes, lawyers for the former treasury secretary had in court papers said his "privacy, confidentiality, and proprietary interests" should take precedence over full disclosure.

S&P has been seeking more information about the government's response to its Aug. 5, 2011 decision to take away the United States' "triple-A" credit rating.

It has said Geithner angrily told McGraw Hill Chairman Harold "Terry" McGraw on an Aug. 8, 2011 phone call that he was "accountable" for an alleged $2 trillion math error, and S&P's conduct would be "looked at very carefully."

The case is U.S. v. McGraw-Hill Cos et al, U.S. District Court, Central District of California, No. 13-00779.

(Reporting by Jonathan Stempel in New York; Editing by Lisa Shumaker)

By Jonathan Stempel