Peter Bergen is CNN's national security analyst, a vice president at New America, and a professor of practice at Arizona State University. He is writing a book for Penguin/Random House about the Trump administration's national security team and its policies. The opinions expressed in this commentary are his own. View more opinion at CNN.

The latest salvo in that war came on New Year's morning -- not traditionally a time for recrimination -- in a presidential tweet that denigrated retired Gen. Stanley McChrystal. Trump tweeted, "'General' McChrystal got fired like a dog by Obama. Last assignment a total bust. Known for big, dumb mouth. Hillary lover!"

This tweet followed an interview that McChrystal gave to ABC's Martha Raddatz on Sunday in which he described Trump as both immoral and dishonest.

McChrystal had led Joint Special Operations Command during the Iraq War and had turned it into one of the most efficient killing machines in history. McChrystal later resigned as the commander of the Afghan War in 2010 following disparaging remarks that some officers on his staff had made to a Rolling Stone reporter about top officials working for President Barack Obama.

Trump is known for being a counterpuncher, so on one level it's not surprising he reacted this way to McChrystal's withering criticism.

But when you step back, the degree to which Trump is battling America's generals is startling, considering how he began his presidency. Trump came into office besotted by military brass, appointing retired four star Gen. James Mattis as his secretary of defense, retired four star Gen. John Kelly as his secretary of homeland security and later chief of staff, and retired three star Lt. Gen. Mike Flynn as his national security adviser. After Flynn was forced out of the White House, Lt. Gen. H.R. McMaster assumed the role of national security adviser.

Now, two years later, Trump is eager to tear down the generals. After Mattis announced his resignation with a letter distancing himself from Trump's key foreign policy positions on December 20 and said that he would stay in the job until the end of February to allow for an orderly transition, Trump instead pushed him out at the end of December.

The differences between Trump and US military leaders are more than simply stylistic, although Trump's lack of decorum and rudeness are certainly at odds with the military's honor-based values.

The military tends to want to sustain overseas military commitments, which they see as vital to securing world order, whether that is to defeat ISIS, or to contain a nuclear-armed North Korea, or to prevent Afghanistan from reverting into control by the Taliban.

Trump believes he was elected to end foreign entanglements and that alliances like NATO are "ripping off" the United States, while US military leaders are keenly aware that NATO allies have been fighting shoulder-to-shoulder with them since the 9/11 attacks.

The policy differences between Trump and the military were underlined by Mattis's resignation, which came as a result of Trump announcing a total withdrawal of the 2,000 US troops in Syria. Mattis appears to have resigned because this decision was made in an arbitrary way and without consulting allies. The Kurds who have been fighting ISIS in Syria on behalf of the United States risk being left defenseless on the battlefield by this move, which potentially subjects them to attack by superior Turkish forces that regard them as terrorists.

When Mattis announced his resignation, Trump tweeted , "When President Obama ingloriously fired Jim Mattis, I gave him a second chance. Some thought I shouldn't, I thought I should."

It is true that Mattis' term as head of Central Command was wound up early by the Obama administration, but far from merely giving Mattis a "second chance," Trump was quite eager to install Mattis as secretary of defense. He told reporters in mid-November 2016 after he had interviewed Mattis for the job, "He's just a brilliant, wonderful man. What a career! We're going to see what happens, but he is the real deal."

A similar trajectory to how Trump treated Mattis also happened with John Kelly. In late July 2017, Trump tweeted "I am pleased to inform you that I have just named General/Secretary John F Kelly as White House Chief of Staff. He is a Great American...." Over time the bromance fizzled -- as it so often does with Trump -- and Kelly, no longer on speaking terms with the President, left as chief of staff at the end of December.

McMaster was also eased out by Trump following comments he made at the Munich Security Conference in late February, in which he described the recent American indictments of Russian officials for interference in the 2016 US presidential election as "incontrovertible" evidence that they had interfered in the election, something the President has always been reluctant to admit.

Trump then tweeted , "General McMaster forgot to say that the results of the 2016 election were not impacted or changed by the Russians and that the only Collusion was between Russia and Crooked H, the DNC and the Dems. Remember the Dirty Dossier, Uranium, Speeches, Emails and the Podesta Company!"

McMaster retired six weeks later.

In November, Chris Wallace of Fox News asked Trump about retired Adm. Bill McRaven's comments that Trump's attacks on the news media were "the greatest threat to democracy in my lifetime."

Stay up to date... Sign up for our new newsletter. Join us on Twitter and Facebook

Trump told Wallace that McRaven was a "Hillary fan," and when Wallace pointed out that McRaven was the architect of the raid that killed Osama bin Laden in Pakistan in 2011, Trump asked, "Wouldn't it have been nice if we got Osama bin Laden a lot sooner than that, wouldn't it have been nice?" This was a bizarre comment to make about what is arguably one of the greatest intelligence and special operations victories in American history.

Trump has now made a sharp break with Kelly, Mattis, McChrystal, McRaven, and McMaster, some of the leading American generals and admirals of our era.

Why Trump, even given his policy disagreements, would pick a war with the military leaders he once so publicly admired is a puzzle that future historians will surely try to unpack.