Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you do partial commit in TortoiseGit?

Tags:

tortoisegit

Native git allows partial commits: You can commit only some of the lines of your file and leave the rest for a later commit.

Is this possible in TortoiseGit?

like image 299
Andy Joiner Avatar asked Sep 11 '15 15:09

Andy Joiner


People also ask

How do you commit in TortoiseGit?

Select any file and/or folders you want to commit, then TortoiseGit → Commit.... The commit dialog will show you every changed file, including added, deleted and unversioned files. If you don't want a changed file to be committed, just uncheck that file.

What is partial commit in git?

For those who use Git Extensions: In the Commit window, select the file you want to partially commit, then select the text you want to commit in the right pane, then right-click on the selection and choose 'Stage selected lines' from the context menu.


2 Answers

Yes, there are official instructions in the docs.

In practice, I find this workflow useful:

  • Right click a file you want to partially commit
  • Click Restore after commit - This immediately creates an internal copy of the file.
  • Double click the file to edit in TortoiseGitMerge
  • Right click -> Mark this block for each change you want to commit now
  • Right click -> Leave only marked blocks to revert the other changes.
    As an alternative to these two steps, you can edit the file the way you want.
  • Save and Close TortoiseGitMerge
  • Commit - this restores the internal copy of the file afterwards.
  • The changes you just reverted in TortoiseGitMerge are now restored in your working tree.

enter image description here

like image 163
Andy Joiner Avatar answered Oct 30 '22 21:10

Andy Joiner


The answer https://stackoverflow.com/a/32527098/3906760 is basically correct, however there are fewer steps required.

  • Choose Restore after commit in the context menu of the file you want to partially commit - This immediately creates an internal copy of the current state of the file.
  • Now adjust the file to only contain the changes you want to commit
    • This can be done using any editor you want to use, but also using TortoiseGitMerge:
      • Double click the file to edit in TortoiseGitMerge (or your configured diff tool)
      • Adjust the file to only contain the changes you want to commit.
      • Save and Close
  • Commit - this commits the selected files and restores the internal copy of the file - the original state of the file is now in your working tree again.

These steps are required as TortoiseGit does not yet support the full staging process and hunk/block selection, cf. https://tortoisegit.org/issue/2299.

like image 29
MrTux Avatar answered Oct 30 '22 21:10

MrTux