How to execute a line line in git gui, although the warning "There is no new line at the end of the file"

I use git gui to select strings for staging for commit. This usually works like a charm. I am aware of the ability to do the same on the command line.

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

Git gui

Problem

The problem that arises due to the lack of a row is that one can no longer create and commit individual rows . When I right-click to select a specific line and select Stage line for commit from the context menu, an error message will appear.

error: fatal: damaged line on line 11.

The problem is not specific to the operating system and can be reconfigured on Windows, MacOSX and Linux. I know that I can avoid the problem if I add a new line to the file and pass this version before continuing on separate lines.

Steps to reproduce the problem

  • Initialize a new repository.
  • Create a file with three lines of content with the word "Hallo". Do not put a new line at the end of the file.
  • Add and commit the file.
  • Edit the same file by inserting words between three lines.
  • Open git gui and try to make changes line by line.

Request

I wonder if there is some kind of configuration for git that allows me to work around the problem. Some automation, such as a hook that adds the desired new line, will also be fine.

error reporting

I sent an error report to the git mailing list. You can follow and participate in the discussion here .

+4
source share
2 answers

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


Finally, gitgui-0.18.0 was merged into git v1.8.4 and is part of the official release (August 23, 2013). Now everyone can use intermediate content, regardless of the new line at the end of the file. Thanks again Heiko!

+5
source

I found a pre-commit hook that takes care of the problem. Although this is not an ideal solution, since the fix is ​​applied until you actually commit the file. I created a gist for the script so you can change it if you want to improve it.

The original script was published by Matt Baker . I reduced it to the fact of adding a new line , but also included routines to remove trailing spaces . However, there is one change with respect to the line symbol: I added \n contrary to Matt's recommendation.

Problem:

I used the script in the git substitution workflow. This caused git to modify all files that have trailing spaces. This led to a big difference. Therefore, I recommend thinking with a script.


Also, I found this discussion on how to integrate interceptors into multiple repositories is quite interesting. You may want to learn this when setting up your own hooks.

+3
source

Source: https://habr.com/ru/post/1444008/


All Articles