-
Notifications
You must be signed in to change notification settings - Fork 0
Cheatsheet: Git for Simutrans
This cheatsheet assumes that your Github repository is set up as origin
git switch <MY-BRANCH>
The old way was git checkout <MY-BRANCH>
but that's confusing terminology and if shares a name with a file or a commit then unexpected things can happen.
git diff <A-BRANCH>..<ANOTHER-BRANCH>
git switch -c <MY-BRANCH>
which replaced
git checkout -b <MY-BRANCH>
git fetch --all
git checkout --track <THEIR-REPO>/<THEIR-BRANCH>
git push -u origin <MY-BRANCH>
git merge <OTHER-BRANCH>
If you want to retain changes in the present working directory, as though you had edited but not committed them:
git reset --soft HEAD~1
If you want to delete the changes forever:
git reset --hard HEAD~1
git name-rev <SHA>
git revert <SHA1 SHA2 etc.>
Git will then prompt you to edit any files that have conflicts. When you have done this:
git revert --continue
If you want to abandon editing while there are still conflicts:
git revert --abort
git remote add <NEW-REPO> <http://THEIR.REPO.URL>
git branch -u <THEIR-REPO>/<THEIR-BRANCH>
Make sure that you are on the branch that you want to use
git switch <MY-BRANCH>`
In the following, change master
to main
if the repository uses that
git reset --soft $(git merge-base master HEAD)
git commit -m "<MY-COMMIT-MESSAGE>"
There should not be an any need to git add
with this approach.
If this branch has already been pushed to a remote, you will probably need to use git push --force-with-lease
to force this push. This is not advised if other people could have already pulled from the remote (e.g. to assess a PR), which you should be warned about with if you use --force-with-lease
rather than the riskier -f
or --force
.
Change main
to master
if the repositories predate that change
If necessary, add the upstream repository as upstream
git remote add upstream https://github.com/<THEIR-USERNAME>/<THEIR-REPO>.git
First, critical, step is to make sure that you are on your main branch and have committed any changes!
git status
git fetch upstream
git rebase upstream/main
You now need to push these changes to your own repo on GitHub. Use --force
because otherwise git prefers the GitHub version
git push origin main --force
If necessary, rebase the branch you are working on
git checkout <BRANCH-NAME>
git rebase main
To get the commit history of line 15 of simworld.h
in the present working directory:
git log -L15,+1:'./simworld.h'
To get the history of the 5 following lines
git log -L15,+5:'./simworld.h'