[cmake-developers] git doesn't let me push: bad whitespace at end of line

Michael Wild themiwi at gmail.com
Sun May 2 04:51:50 EDT 2010


On Sat, May 1, 2010 at 4:49 PM, Eric Noulard <eric.noulard at gmail.com> wrote:

> 2010/5/1 Alexander Neundorf <neundorf at kde.org>:
> > Hi,
> >
> > I tried to push a commit to master, but this failed because git
> complained
> > that the patch adds a trailing whitespace in one line.
> > So I removed this whitespace and committed this.
> > But git still doesn't push, I guess because the commit which adds the
> > whitespace is still there:
>
> I did have that trouble once.
>
> What I did was:
>     1) save a diff between offending commit and the current tree.
>         git diff <commitid-ok> HEAD > put-aside.patch
>
>     2) reset the clone to commit-ok
>         git reset --hard commitid-ok
>
>     3) apply the put aside patch
>
>     4) fix the offending space
>
>     5) commit
>
>     6) push
>
> This may not be the most easiest way to do it but it worked for.
> I would be glad to know 'the definitive right way to do it'...
>
>
>
Much too complicated ;-)

If the offending commit is also HEAD, use "git commit --amend". If the
commit is older, you can use the following:

- "git rebase --interactive $OFFENDING_COMMIT^"
  (where $OFFENDING_COMMIT) is commit-ish for the offending commit
  (e.g. the hash or some other reference). Then, in the editor that pops up
  (likely vim or whatever is the default setting on your system), identify
the
  line with the offending commit and change the character in the first
column
  to "e". Save and quit.
- Now, git will take you to that commit and you can make the appropriate
changes
- "git commit --amend"
- "git rebase --continue".
- "git push"

If you already made a commit that fixes the issue, you can "squash" it with
the original, offending commit by using "git rebase --interactive",
rearranging the lines such that the commit with the fix is just below the
offending commit, and then change the first character in the line of the fix
to "s" (for squash). Save and quit and git will replay the history and
squash the fix into the offending commit (like "commit --amend"), giving you
the opportunity to modify the commit message.

Just make sure to not rebase beyond the last merge, that's asking for
trouble (unless, of course, you know exactly what you're doing and read "git
help rebase" very carefully)

HTH

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20100502/f83a4fe5/attachment.html>


More information about the cmake-developers mailing list