I'm a relative newcomer to Git, but I've been learning some more advanced stuff as I've been working on a game design competition. In the process of trying to splice changes between two branches, I've been introduced to git checkout --patch
, which would do exactly what I need it to. However, despite the fact that simply applying hunks with y
or n
will work, as will splitting, any time I choose to manually edit a hunk with e
, it consistently fails. Take, for example, this patch:
# Manual hunk edit mode -- see bottom for a quick guide
@@ -102,12 +80,12 @@ enum Facing {
int stunTimer;
int m_health;
- bool m_softStun = true;
bool hitFlag;
bool jumpFlag;
SoundGroup contactSounds;
float movementInput;
+ float verticalInput;
[SerializeField]
public GameObject opponent;
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for applying. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.
This is a simple patch whose problem I could solve by splitting, but I will use it as an example. Say I attempt to keep both the m_softStun
bool, and verticalInput
float variables. It should seem like all I need to do is this:
# Manual hunk edit mode -- see bottom for a quick guide
@@ -102,12 +80,12 @@ enum Facing {
int stunTimer;
int m_health;
bool m_softStun = true;
bool hitFlag;
bool jumpFlag;
SoundGroup contactSounds;
float movementInput;
+ float verticalInput;
[SerializeField]
public GameObject opponent;
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for applying. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.
All I have done is remove the -
in front of bool m_softStun
and, as documentation and other answers have told me, add a space.
However, when I try to apply this patch, it returns to me an error:
error: patch failed: Assets/Scripts/Fighter.cs:23
error: Assets/Scripts/Fighter.cs: patch does not apply
This error, or variations with different line numbers, has returned to me through all of the following attempts to fix it:
- I have used standard Windows 10 Notepad, Notepad++ and even Vim
- I have checked to make sure there is no whitespace being consumed by a tab at the beginning, even going into Vim's hexadecimal analysis to ensure it
- I have tried removing and keeping carriage returns from the ends of the lines
- I have tried to encode in both ANSI and UTF-8 via Vim, Notepad and Notepad++
- I have tried not editing the patch at all, which still gives me an error, leading me to suspect it is either an error in git, or in the way I'm saving files.
I'm practically at my wit's end trying to figure out what's gone wrong, but I don't have the technical knowledge to even start to find out. Even my local 'git guy', who suggested such things as the hexadecimal checking, has been unable to help, and sent me to e-mail a bug report which has so far turned up nothing. Does anyone have any clue why I can't make a manual patch?