Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stage line by line in git gui although "No newline at end of file" warning

I use git gui to select lines for being staged for a commit. This normally works like a charm. I am aware of the option to do the same on the command line.

Whenever a file does not initially have a new line at the end of the file git gui recognizes this and appends a warning message in the editor as I illustrated in the screenshot.

Git Gui

Problem

The problem which results from the missing line break is that one can no longer stage and commit individual lines. When I right-click to select the specific line and choose Stage line for commit from the context menu an error message pops up.

error: fatal: corrupt parch at line 11.

The problem is not specific to the operating system and can be repoduced on Windows, MacOSX and Linux. I know that I can avoid the problem if I add a new line to the file and commit this version before I continue selecting individual lines.

Steps to reproduce the problem

  1. Initialize a new repository.
  2. Create a file with three lines of content each with the word "Hallo". Do not put a new line at the end of the file.
  3. Add and commit the file.
  4. Edit the same file putting words inbetween the three lines.
  5. Open git gui and try to stage the changes line by line.

Request

I wonder if there is some configuration for Git which allows me to circumvent the problem. Some automatism such as a hook which adds the desired new line would also be fine.

Bug report

I sent a bug report to the Git mailing list. You can follow and participate in the discussion here.

like image 856
JJD Avatar asked Nov 04 '12 23:11

JJD


People also ask

How do I stage a file in Git GUI?

You can open Git Gui by clicking “Git GUI Here” in the folder's context menu. Now add a plain text file to your project folder and click the “Rescan” button in Git Gui. The file will show up in the top-left pane. The “Stage Changed” button will add all changed files to the staging area.

What git add does?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


1 Answers

Thanks to Heiko Voigt there is a bugfix for the behavior. We fixed this at the Git-Merge conference - thanks to GitHub for organizing this. The patch is pending on the mailing list at the moment. As soon as it is merged and released I am going the update this post here.

  • http://www.mail-archive.com/[email protected]/msg25556.html
  • http://github.com/hvoigt/git/tree/hv/git-gui-fix-no-newline

Finally, gitgui-0.18.0 has been merged into git v1.8.4 and is part of the official release (Aug 23, 2013). Now everybody can enjoy staging linewise commits regardless of a new line at the end of the file. Thanks again to Heiko!

like image 95
JJD Avatar answered Sep 23 '22 19:09

JJD