Hi Rocky,
You are making good progress and have not yet lost/overwritten anything
(permanently)
On 17/05/2019 18:16, Rocky Ji wrote:
I am working individually at the moment.
I have the habit of committing related changes on a regular basis, but
I push to GitLab only at the end of class session.
That is OK.
-------Events to reproduce the situation--------
Thursday, in school:
- `git clone https://gitlab.../my-repo`
[ here you have forgotten that you can/should create a branch for the
feature you are developing - more in a moment]
- create a few .rst documentation files
- commit the above changes
Good.
before I `git push -U origin master`
This (-U) may not be the best option. You do not really have an
'upstream' if you are not collaborating.
Just 'push origin' (branch name)
Friday, in school:
- start working on new feature,
new feature -> new branch. You can merge them when you are ready.
create a test file `test_A.rb`
- I commit the changes
good
but forget to push
So here you have the commit store on that machine, but no copy on GitLab
Sunday, **in home**:
- I `git clone https://gitlab.../my-repo`
Ah, you now have a second "downstream" PC. Note that it only has the
first feature because you didn't push
- work on the exciting new feature that popped in my head, create
`feature.rb`
If it is on its own branch, everything is easier.
- commit the changes before I `git push -U origin master`
Again, -U may not be what you need - you don't need to set the
'upstream' every time.
What you now have is feature 1 , and feature 2, on top of master.
If they were separate branches you would now have 'master', 'feature1'
and 'feature3' at Gitlab as separate lines of development ready to merge.
Monday, in school:
- running `git status` shows `Your branch is ahead of 'origin/master'
by 1 commit.`
Well yes. Gitlab has feature1 and feature 3 on top of master, but your
school machine has feature1 and feature 2 on top of its master.
you can fetch from gitlab, and in the "remote tracking branch (rtb)"/
(the branch that tracks what's on the remote" you will have a branch
(normally not shown unless you use 'branch -a'), called
remotes/origin/master. It will have feature1 and feature3 on it. It is
already inside you school machine.
You could be brave and create some branches for feature1, etc (but I
would just wait...)
However what is easier is, on master branch simply merge in that
origin/master remote branch. The new merge commit will have all the
changes. Use gitk or a suitable viewer to see the structure with the
side loop of the merge.
--------end problem reproduction----------------
Questions I have
1. What will happen if I follow Git's recommendation `use "git push"
to publish your local commits`?
Don't, at this stage. You need a better understanding of what is held
where and when to use the advice.
2. How do I resolve this situation? I don't want loose any information
i.e. preserve `test_A.rb` and `feature.rb` along with their commit
messages and timestamps.
see above - merge origin/master
3. Why does Git assume that local-working-dir is "ahead" without
consulting the Gitlab server first?
A) maybe it did but you didn't see the quick exchange of details, or b)
you already had the two different versions (have you shown all the steps
- maybe a pull that failed at school (which does the fetch, then
attempts the 'merge')
4. How to make Git "consult" (but not mess the working-dir) GitLab
repo before starting my day's work?
Git fetch (maybe with a --all) check the 'refspec' in your config file.
see 'git help glossary' for the terms, and 'git help revisions'..
--
Philip
--
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 git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/git-users/c4d4d46e-b226-97d2-378e-18967dad2c59%40iee.org.
For more options, visit https://groups.google.com/d/optout.