Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit a partial file (hunks) to git in pycharm

Tags:

git

pycharm

I'm a heavy Eclipse PyDev + EGit user and looking to switch to PyCharm. In Eclipse, I can choose to add only certain hunks/lines of a file to the git index, the same as using git add -p from the terminal. I find doing it through a GUI to be faster, and I have been looking for the same functionality in PyCharm. Does it exist? Thanks

like image 209
mach Avatar asked Jan 21 '14 16:01

mach


People also ask

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.

How do I commit a file in PyCharm?

Commit changes locally As your changes are ready to be committed, select the corresponding files or an entire changelist. If you press Ctrl+K , the entire active changelist will be selected. You can also select files under the Unversioned Files node — PyCharm will stage and commit these files in one step.

How do I commit in PyCharm terminal?

Starting from PyCharm version 2020.1, you can switch to a non-modal commit interface: select the Use non-modal commit interface option (enabled by default for new installations) on the Version Control | Commit page of the IDE settings Ctrl+Alt+S .


2 Answers

This is not currently supported. Follow this ticket for details (comment/watch to be notified when it will be implemented).

http://youtrack.jetbrains.com/issue/IDEA-63201


UPDATE 2018-03-13:

This functionality is now implemented (more or less) and will be available in 2018.1 version. A bit more can be found in this blog post.

like image 55
LazyOne Avatar answered Sep 24 '22 22:09

LazyOne


PyCharm manages this through change lists. Here is an example.

  1. We create a new change list from an existing one (one that we've already created, or the default changelist).
  2. We make a couple of changes and hit VCS -> Commit Changes
  3. In the diagram below at {1}, you can see that the changelist is set to Default, and in {2} you can see the actual change. Right click on {2} and select the change.

enter image description here

Now, say we want to commit only this change. We can do this by adding it to a new changelist, by clicking on {3}, and this will pop up:

enter image description here

Since we don't have a new one, let's just create a new changelist using the dialog box. And then let's change the currently selected changelist to New Changelist:

enter image description here

Notice that there is only one file, with one change, just like our changelist. How about we add a few things from the default changelist to the new one:

enter image description here

Now, let's head back to the New Changelist:

enter image description here

Now that we're done with our selective changes, press Commit. After this, we can push:

enter image description here

I pushed to bitbucket, so let's see the changes:

enter image description here

As you can see, only the stuff in the New Changelist was added.

like image 30
Games Brainiac Avatar answered Sep 22 '22 22:09

Games Brainiac