1

I am trying to remove a small amount of lines of a diff with git patch -p foobar. The resulting chunk is like this (without git's comments):

@@ -142,4 +150,26 @@
  {
    perr( "fcntl" );
+   return stream_s();
+ }
+ return stream;
+}
+
+int pid_read( stream_s* data, unsigned char* buff, size_t max_siz, size_t *rd_size )
+{
+ assert( data );
+ ssize_t rd = read( data->fd, buff, max_siz );
+ if( rd < 0 )
+ {
+   return waitpid( data->pid, NULL, WNOHANG ) <= 0;
+ }
+ *rd_size = static_cast<size_t>( rd );
+ return 1;
+}
+
+string_list_t pkg_list( char const* script )
+{
+ stream_s stream;
+ if( ( stream = init_command( script ) ) == stream_s() )
+ {
    return string_list_t();
  }

The block I would like to remove is the function pid_read. So, following the quick guide, just removing those lines should be ok, but in effect, git refuses the change saying that the patch could not be applied cleanly. No more information.

I've tried to reproduce the problem on a smaller sample, but I can't... It's not the first time I have this problem, and usually I "solve" it by doing the change manually, but it's not really nice when the change is more complex.

user3459474
  • 145
  • 1
  • 7

1 Answers1

1

That would require some line number tinkering for the edited hunk to apply. (the @@ -142,4 +150,26 @@ part)

An easier path to apply an edited hunk is to try and:

  • edit and remove everything but the first part (which is the part before the section you don't want)
  • then make a second patch where you remove the all first part (including the section you don't want), leaving only the part after the section you don't want.

See if those two patches can apply.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Strange... when I tried first, even changing the @@ line, it didn't worked. I've skipped it, and now just redoing it, and it works. The only difference I can see is that at first, I had other previous changes which were accepted, unlike the second time. At least it works now. Thanks. – user3459474 May 18 '16 at 06:40
  • @user3459474 redoing the line tinkering? Or another manipulation? – VonC May 18 '16 at 06:41
  • At first, I had other parts in the same file that had informations to accept/reject. Editing that part didn't worked then, even with tinkering the @@l line. So I just put that aside while doing some more code, and tried after your reply. There was only that part to alter, and it worked. I guess the problem I had was because of the fact lines had changed more that what git said in the @@ line, which could have cause some conflict? – user3459474 May 18 '16 at 06:55
  • @user3459474 Yes, that is what I suspect when reading http://stackoverflow.com/a/3270837/6309 – VonC May 18 '16 at 06:56