15

I am new in GitHub for Windows. I learn how to commit a single change. But i don't understand how can i commit only a part of file. On GitHub for Mac you can just select the line.

How can i do it on GitHub for Windows?

FrancescoMussi
  • 20,760
  • 39
  • 126
  • 178
  • Did you look in the help pages? – kyle k Aug 29 '13 at 17:06
  • Ok, is not supported yet. This is what they reply from the support: Hi Francesco, Currently we don't support line-by-line staging, but this is something we'd like to add in the future to GitHub for Windows. Thanks for letting us know you'd like to see it. Cheers, Steve – FrancescoMussi Aug 29 '13 at 19:18
  • git add? then commit? – progrenhard Aug 29 '13 at 19:31
  • Hey man, if you read the title, there is written: How to commit ONLY A PART of the file – FrancescoMussi Aug 30 '13 at 06:20
  • 1
    Update January 2015: GitHub for Windows has just implemented just that! See my [edited answer below](http://stackoverflow.com/a/18531719/6309). – VonC Jan 15 '15 at 07:22
  • Discussion to improve the discoverability of staging line-by-line in GitHub Desktop: https://github.com/desktop/desktop/issues/1688 – pkamb Aug 03 '17 at 18:47

2 Answers2

20

Update: January 2015, 14th: Partial commits in GitHub for Windows:

The newest release of GitHub for Windows supports selecting lines or blocks of changes when creating a commit. Simply click the desired lines in the gutter, create the commit, and leave the other changes for you to continue working on.

https://cloud.githubusercontent.com/assets/359239/5745722/ab3d336e-9bdf-11e4-8001-fc7316e8155b.gif

The GitHub post adds what I mentioned in my original answer below:

For people familiar with the command line, this change is similar to interactive staging using git add -i or git add -p.


(Original answer: Aug. 2013)

From GitHub for Windows, you can open the console, and type:

git add -p -- path/to/your/File

You will then be able to stage exactly what you want from that file.

git add --patch:

Interactively choose hunks of patch between the index and the work tree and add them to the index.
This gives the user a chance to review the difference before adding modified contents to the index.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

I know I am a bit late on this thread. But I was facing an issue where the selected code block was not getting added when I click on the line I wanted to include in the commit. Just make sure you've disabled the Hide whitespace changes checkbox in the settings menu.

enter image description here

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29