The hardest part of Git is getting your mental model right. The idea that 
there can be different copies at different places each with apparently the 
same 'easy name' (like 'master') can be hard to grasp, especially in the 
heat of the moment.

The true 'name of each of the copies is given by it's SHA1 object id (oid). 
You will see that if they are identical then they will have the same oid. 
If they are different then their oid is guaranteed(*) to be different.

So you had something ready 'on master' and sent a copy to your remote. 
Great.two copies both on master at their respective pc/servers.

You then changed your copy locally (it gets a new oid) and try to sent that 
different thing to be an *extra *part of the old thing, but it was refused 
because it was a 'swap one out' amendment, when it expected an incremental 
improvement. (the solution would have been to 'force' it, once you 
understood what happened).

The repository / object store is write only - it doesn't actually amend 
anything !!! Instead it just has a local friendly name that then 'points' 
to the correct object. Commit objects know who their parents were, and the 
objects in their directory tree, hence all of history is there.

This 'friendly name' (branch and remote names) is a mental model thing. Do 
have a look for explanations that highlight the mental model and how 
mistakes happend



(*) the sha1 was 'cracked' for a few very special cases using thousand of 
years of CPU time, but Git survived as it had extra protection. Git is 
working on a plan to transition to a 256 bit object id.

On Tuesday, May 5, 2020 at 3:00:23 AM UTC+1, SJW wrote:
>
> git is doing my head in.  I started using it thinking it would help but it 
> just seems to add extra time and headache to projects that wasn't there 
> before.  Almost every time I try to update a repo, I get an error that 
> confueses the hell out of me... I have come to the conclusion that I am 
> clearly too stupid to use git but thought I would post here before writing 
> it off forever.
>
> All I know of git is what I've learnt on YouTube videos.
>
> Today I added 5-6 files that I had edited into the master branch
>
> git add .
>
> Then I committed and pushed to origin
>
> git commit -m 'Updates...'
>
> [master 0cc8698] Updates...
>  7 files changed, 673 insertions(+), 334 deletions(-)
>  create mode 100644 classes/class.email.php
>
> git push origin master
>
> Counting objects: 12, done.
> Delta compression using up to 4 threads.
> Compressing objects: 100% (12/12), done.
> Writing objects: 100% (12/12), 3.54 KiB | 0 bytes/s, done.
> Total 12 (delta 10), reused 0 (delta 0)
> To https://gitlab.com/SJWGL/project.git
>    9837efd..0cc8698  master -> master
>
> Then, as I was closing all the files, I noticed some comments I had left 
> in a couple of files and wanted to just clean up which I did.
>
> $ git status
> On branch master
> Changes not staged for commit:
>   (use "git add <file>..." to update what will be committed)
>   (use "git checkout -- <file>..." to discard changes in working directory)
>
>         modified:   api/process.booking.php
>         modified:   classes/class.logger.php
>         modified:   configuration.php
>
> no changes added to commit (use "git add" and/or "git commit -a")
>
>
>
> I then tried to add the small changes to the previous commit as they dont 
> need their own commit.
>
> $ git add .
>
> $ git commit --amend
> [master 54c1612] Updates...
>  Date: Tue May 5 10:16:30 2020 +1000
>  9 files changed, 681 insertions(+), 340 deletions(-)
>  create mode 100644 classes/class.email.php
>
> $ git push origin master
> To https://gitlab.com/SJWGL/project.git
>  ! [rejected]        master -> master (non-fast-forward)
> error: failed to push some refs to 'https://gitlab.com/SJWGL/project.git'
> hint: Updates were rejected because the tip of your current branch is 
> behind
> hint: its remote counterpart. Integrate the remote changes (e.g.
> hint: 'git pull ...') before pushing again.
> hint: See the 'Note about fast-forwards' in 'git push --help' for details.
>
>
> So I follow the instructions:
>
> $ git pull origin master
> From https://gitlab.com/SJWGL/project
>  * branch            master     -> FETCH_HEAD
> Auto-merging api/process.booking.php
> CONFLICT (content): Merge conflict in api/process.booking.php
> Automatic merge failed; fix conflicts and then commit the result.
>
>
> Then I fumble my way through just to try and get the file into repo but 
> obviously there is a problem that I dont know how to manage...
>
> $ git diff
> diff --cc api/process.booking.php
> index efd3e11,9e9eed8..0000000
> --- a/api/process.booking.php
> +++ b/api/process.booking.php
> @@@ -79,7 -79,6 +79,10 @@@ else
>
>
>   endif;
>
>
> ++<<<<<<< HEAD
>  +// If no errors, send email
> ++=======
> ++>>>>>>> 0cc8698b634303b68e8a8568af503ed7576e3cc2
>   if ($sendEmail) {
>         $email = new Email();
>         $email->setBookingData($booking->getBookingData());
>
> $ git push origin master
> To https://gitlab.com/SJWGL/project.git
>  ! [rejected]        master -> master (non-fast-forward)
> error: failed to push some refs to 'https://gitlab.com/SJWGL/project.git'
> hint: Updates were rejected because the tip of your current branch is 
> behind
> hint: its remote counterpart. Integrate the remote changes (e.g.
> hint: 'git pull ...') before pushing again.
> hint: See the 'Note about fast-forwards' in 'git push --help' for details.
>
> $ git status
> On branch master
> You have unmerged paths.
>   (fix conflicts and run "git commit")
>   (use "git merge --abort" to abort the merge)
>
> Unmerged paths:
>   (use "git add <file>..." to mark resolution)
>
>         both modified:   api/process.booking.php
>
> no changes added to commit (use "git add" and/or "git commit -a")
>
> $ git add .
>
> $ git commit --amend
> fatal: You are in the middle of a merge -- cannot amend.
>
> $ git commit
> [master a32b8a9] Merge branch 'master' of https://gitlab.com/SJWGL/project
>
> $ git push origin master
> Counting objects: 11, done.
> Delta compression using up to 4 threads.
> Compressing objects: 100% (11/11), done.
> Writing objects: 100% (11/11), 1.20 KiB | 0 bytes/s, done.
> Total 11 (delta 9), reused 0 (delta 0)
> To https://gitlab.com/SJWGL/project.git
>    0cc8698..a32b8a9  master -> master
>
>
> I dont know that the f**k I'm doing???
>

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/c1f4ed7b-5d45-4e74-85f6-0a2ac3732322%40googlegroups.com.

Reply via email to