(Sorry for top posting. I have no choice but to use Outlook right now.)

Git pull does a merge by default. Here is the best way to think about it.

Let's say A, B, and C are the three most recent commits to curl master on 
github. C is at the tip of the tree. Looking at github master the commits look 
like this:

C <--- master
|
B
|
A

In your case you are *behind* master, so perhaps your tree looks like this:

B <--- Your local master
|
A

You commit change D (your curl_socket_t change) to your local master:

D <--- New local master
|
B
|
A

When you do git pull, a merge is performed:

E <--- New local master
|
D
|
B
|
A

Change E is a result of applying change C on top of change D.

The reason github won't accept your changes is that it would have to undo C and 
apply D and E to accept your changes. That would invalidate existing commits in 
the tree -- which is OK for personal projects, but in the case of a big 
project, old git commits should never go away.

Instead of pulling, do 'git pull --rebase' or 'git fetch origin' followed by 
'git rebase origin/master'. This causes the following to happen locally:
                                        D'
                                        |
    D                      C            C
    |                      |            |
    B          B           B            B
    |          |           |            |
    A          A           A            A

  Begin      Rewind    Fast-forward   Rebase

When you rewind, you revert locally to the last commit that is shared by both 
you and github.

Then, the rebase process fast-forwards your tree to the latest changes from 
github.

Finally, the rebase concludes by applying change D on top of everything else - 
which may involve merge conflicts - so the new change is D'.

Now, if you re-push, and github's head is still at C, it can accept change D' 
with *absolutely no risk* of merge conflict, and there is no need to undo 
existing changes to do that.

Does that make sense?

-Josh

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Yang Tse
Sent: Tuesday, June 08, 2010 5:35 PM
To: [email protected]
Subject: git stuff

I changed tftp.c locally and used "git diff" to verify nothing strange
would get committed...

$ git diff
diff --git a/lib/tftp.c b/lib/tftp.c
index c02337f..a1c0e25 100644
--- a/lib/tftp.c
+++ b/lib/tftp.c
@@ -1199,7 +1199,7 @@ static CURLcode tftp_easy_statemach(struct connectdata *co
   CURLcode              result = CURLE_OK;
   struct SessionHandle  *data = conn->data;
   tftp_state_data_t     *state = (tftp_state_data_t *)conn->proto.tftpc;
-  int                   fd_read;
+  curl_socket_t         fd_read;
   long                  timeout_ms;
   struct SingleRequest  *k = &data->req;
   struct timeval        transaction_start = Curl_tvnow();

I commit the change locally with "git commit"...

$ git commit -a -m "fix compiler warning using curl_socket_t to store
socket descriptor"
[master]: created da6e992: "fix compiler warning using curl_socket_t to store so
cket descriptor"
 1 files changed, 1 insertions(+), 1 deletions(-)

I push the change to github with "git push"...

$ git push
To [email protected]:bagder/curl.git
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to '[email protected]:bagder/curl.git'

It fails miserably. Something has been changed in github's repo. So I
do a "git pull"...

$ git pull
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
>From [email protected]:bagder/curl
   feecf63..bb60fe0  master     -> origin/master
Merge made by recursive.
 lib/inet_pton.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Now I push my changes again...

$ git push
Counting objects: 12, done.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 742 bytes, done.
Total 7 (delta 5), reused 0 (delta 0)
To [email protected]:bagder/curl.git
   bb60fe0..d3714b0  master -> master

Everything seems fine on this end.

But... Looking on githubs commit history I find...

http://github.com/bagder/curl/commit/d3714b016d9f88420d17861d4a48f39365bdd961
http://github.com/bagder/curl/commit/da6e992e1dbc2c44c19716ee1ef1f07e4250fd72
http://github.com/bagder/curl/commit/bb60fe0c1af619ff1507424fa2b27dc458a7215b

Why has d3714b016d9 appeared in github?

Wasn't git pull supposed to update my 'distributed' local repo copy
with github's master one?

Which should have been the proper command after I've got the " !
[rejected]        master -> master (non-fast forward)" message?

I'm also posting all operations done in case I've broken something and
needs to be fixed by someone who knows git.

Just for fun... google reports today about 13,500 results for "I hate git"
-- 
-=[Yang]=-
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to