How to create revision for a node programmatically I have node and i need to create revisions for that node programmatically . When i tried as follows :

$node = Node::create([
                'nid' =&gt; $nid, //my desired node id for the revision
                'type' =&gt; $bundle_type,
                'field1' =&gt; value1,
                'field2' =&gt; value2,
]);

$node-&gt;revision = TRUE;
$node-&gt;save();
$node-&gt;setPublished(true);
$nid = $node-&gt;id();
print 'Created revision for node' . $nid;


Its not working , instead its creating new nodes . Any solution for this ?
// Make this change a new revision
  $node->setNewRevision(TRUE);
  $node->revision_log = 'Created revision for node' . $nid;
  $node->setRevisionCreationTime(REQUEST_TIME);
  $node->setRevisionUserId($user_id);
  $node->save();


Use Above Code to create a revision. :)