News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

Git usage

Started by ACarlotti, May 16, 2019, 05:19:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ACarlotti

James: I think you accidentally merged Vladki's master into your master just after writing your post above. This contained no actual changes, just a bunch of unnecessary merge commits.

Vladki: Your master branch on Github contains a number of merges of 'pull requests' from James' master branch, which I don't think belonged. I think this is because you method of trying to get up-to-date with James' master on Github is to create and merge a pull request. Unfortunately this results in the creation of unnecessary merge commits (because Github by default uses no fast-forward option).

A better approach would probably be to fetch James' commits directly onto your local machine (set it as a remote repository, and then use git fetch). For example, I would run "git remote add upstream https://github.com/jamespetts/simutrans-pak128.britainhttps://github.com/jamespetts/simutrans-pak128.britain" (if I haven't already configured the remote repository reference - this only needs to be done once), followed by "git fetch upstream". If everything on your local branch is already on master, then you can simply run "git pull upstream master" to create fastforward your local master to the upstream master; otherwise I would normally use "git rebase --upstream/master master" to rebase my local changes onto the new master to avoid unnecessary merge commits. (This applies mostly for simple changes that other people won't have built upon; if it's a complicated set of changes that you might have uploaded for already for other people to work with, then a true merge might be more appropriate).

I wonder if it might be worth me writing a load of stuff about using Git somewhere? I don't know anything about usage through a GUI however, although avoiding that might avoid many of the issues that I have seen.

Vladki

#1
Hello. I admit that my usage of git is not optimal. I'm a git newbie. So I didn't find any better way to keep up to date that pull requests... I will try what you described, although I'm still not sure what many terms in context of git mean.

An nice howto would be very appreciated.

Moreover, the pull request with the fixes was not merged...

Matthew

I for one would appreciate guidance on using Git for Simutrans-Extended. Something that would be helpful to me would be an explanation of the analogy behind the commands. You kindly explained that if Vladki wants to fetch the latest version from the repository, he must run "git remote add upstream". It is not correct to "pull" the latest version, even though it is being fetched from Github, far away, to become closer to Vladki. I am not saying that "add" is more or less logical than "pull", just that I imagine there is some kind of analogy behind it and the commands would probably be easier to remember in that context. For example, even though Ctrl-X, Ctrl-C, and Ctrl-V are arbitrary, it's helpful to know they're based on a cut-and-paste analogy.

It may be that my mind is addled by Mandarin, where you must often explicitly choose the direction of action (in the same way that English often forces speakers to explicitly choose a tense).
(Signature being tested) If you enjoy playing Simutrans, then you might also enjoy watching Japan Railway Journal
Available in English and simplified Chinese
如果您喜欢玩Simutrans的话,那么说不定就想看《日本铁路之旅》(英语也有简体中文字幕)。

ACarlotti

Quote from: Matthew on May 16, 2019, 09:39:19 PMhe must run "git remote add upstream". It is not correct to "pull" the latest version, even though it is being fetched from Github, far away, to become closer to Vladki.
Oops, I forgot to add in an important point - 'git remote add' only needs to be used once to set up a reference to the remote repository. I've edited my previous post to fix this.
'pull' is effectively 'fetch' followed by 'merge' - I would tend to fetch first to see what is there, and to avoid spurious merge commits; and as mentioned, I would generally rebase onto the latest upstream instead of merging (which is what 'pull' would do) - I think it makes the source history easier to follow in the most common case of simple patches.

Vladki

#4
Perhaps this should be split into new thread about git usage. I vaguely remember that the workflow I used was recommended in some git tutorial. I will post more questions later...

UPDATE:
I am using git and svn only for simutrans related projects. extended prefers git, standard prefers svn. So I am often confused by the exact terms and a bit different workflow.
E.g. svn update = git pull; svn commit = git add + git commit + git push

Before I had a github account I have done "git clone" of james' repository, and updated it with "git pull". That was ok to compile locally, and I was able to produce patches by "git diff" and sending them to forum. However before the next git pull i had to "git stash" my changes, and reapply them manually later. Also the stashes were inconveniently named  Is there a more sensible way to pull upstream changes and merge them with local changes? Is there a way to send pull request with local changes to github?

Later I have signed up for an account on github and created my own fork, so that I could work on bigger projects on separate branches (e.g. smoke-improvements). But then I found it extremely complicated to keep up to date, and the method with pull requests from james' to mine fork was the only I could find. I also think that it is not optimal, but it is the best I have found. Although I was reading the fine manual I still do not have a good grip on the git philosophy and terms (like checkout, merge, rebase,... ) so I even do not know what to look for in the manuals.

So now I have clone of my fork (vladki77 on github) on my computer. How do I update that to james:master without pull request?