Lecture code
English below)
Norsk (Dette repoet inneholder alle filene vi bruker/lager under forelesninger. Etter hver forelesning oppdateres prosjektet med de relevante filene.
Hvordan beholder jeg de lokale endringene mine når nye forelesningsnotater legges til dette repoet?
Hvis du gjør endringer på dette repoet kan det oppstå konflikter hvis både du og foreleser har endre på de samme filene og du så prøver å pulle disse endringene for å oppdatere din klone av repoet.
Hvordan du håndterer dette er avhengig av hva du har tenkt å gjøre med koden:
- Jeg vil gjøre endringer på koden og lagre disse i gitlab.
- Jeg vil gjøre endringer på koden men bare lagre dem lokalt.
- Jeg vil gjøre endringer på koden men ikke lagre dem.
- Jeg vil ikke gjøre endringer på koden.
1. Lag et separat prosjekt med endringer
- Fork repoet og klon forken, eller klon dette repoet direkte.
- Lag ditt eget prosjekt som er tiltenkt endringer. Dette kan være et repo på gitlab som du kloner, eller det kan være bare en lokal mappe hvis du ikke har tenkt å lagre endringer i gitlab.
- Kopier over filene du ønsker fra din klone av lecture_code-repoet og lim dem inn i endrings-prosjektet. Disse kan nå pushes fritt uten problemer.
- Når du vil oppdatere ditt lecture_code repo, bruker du kommandoen
git pull
i terminalen for å pulle nye endringer fra lecture_code repoet. Hvis du har laget ditt eget repo for endringer går du nå inn i dette og trykke på knappen som sier "Update fork". - Kopier over filene du ønsker inn i endrings-repoet ditt. Du har nå ingen konflikter og får beholde endringene dine uten problemer.
2. Bruk pull og håndter konflikter manuelt
Hvis du vil pushe endringene dine til gitlab, bruk den forrige metoden. Denne metoden vil gjøre det vanskeligere.
Den forrige kommandoen bruke git pull
. Ingen konflikter oppstår, fordi ingen endringer hadde blitt gjort på repoet før foreleser lastet opp ny kode. Disse endringene ble holdt i et separat prosjekt. Hvis du ikke har tenkt å pushe endringene dine til git, kan du spare deg selv for å kopiere filer ved å bare bruke git pull
og så manuelt håndtere konflikter. Når du puller filer som lager konflikt, må du gjøre en av to ting først:
Commit eller stash
Å bruke Commit burde vært kjent fra før. Dette er det vi gjør før vi kan pushe endringer til gitlab repoet vårt.
- Hvis du forket dette repoet, gå inn i forken og trykk knappen som sier "Update fork" først.
- Lagre alle filene du gjorde endringer på lokalt i din IDE.
- Bruk kommandoen
git add .
i terminalen for å "stage" endringene. (De fleste IDEer har innebygd funksjonalitet for å stage endringer.) - Bruk kommandoen `git commit -m "YOUR COMMENT HERE" for å commite endringene. IKKE PUSH. Dette kan forårsake mange problemer. Hvis du vil pushe koden, bruk metoden over.
- Bruk kommandoen
git pull
for å hente endringene fra lecture_code repoet. Konflikter kan oppstå her, og du må manuelt velge hvilken versjon du ønsker å beholde.
Å stashe betyr å "legge vekk" de lokale endringene så du kan jobbe på andre ting og hente endringene tilbake når du trenger dem. Denne metoden gjør i dette tilfellet akkurat det samme som å commite (merk at disse kommandoene ikke er ekvivalente).
- Hvis du forket dette repoet, gå inn i forken og trykk knappen som sier "Update fork" først.
- Lagre alle filene du gjorde endringer på lokalt i din IDE.
- Bruk kommandoen
git stash
i terminalen din for å stashe vekk endringene. - Bruk kommandoen
git pull
i terminalen for å hente endringene fra lecture_code repoet. - Bruk kommandoen
git stash pop
for å hente frem igjen endringene du stashet. Konflikter kan oppstå her, og du må manuelt velge hvilken versjon du ønsker å beholde. IKKE PUSH. Dette kan forårsake mange problemer. Hvis du vil pushe koden, bruk metoden over.
3. Slett klonen og klon på nytt
Hvis du ikke føler for å beholde endringene du har gjort på forelesningskoden, kan du enkelt nok slette klonen din og klone når nye endringer lastes opp. Så kan du klone prosjektet på nytt og ta det derfra.
Eventuelt kan du slette alle endringene du har gjort og bruker kommadoen git pull
i terminalen, men om du ikke er nøyaktig og sletter alle endringer, kan det oppstå konflikter.
4. Ikke gjør endringer
Hvis du ikke har tenkt å gjøre endringer på forelesningskoden, men du vil ha prosjektet lokalt, vil det ikke oppstå konflikter og du kan bare bruke kommandoen git pull
i terminalen for å oppdatere klonen din (eller bruke metode 3).
English
This repository contains all files we use/make during lectures. After each lecture we will update the project with the relevant files.
How do I keep my local changes when new lecture notes are added to this repository?
If you make changes to this repo, there might become conflicts if both you and the lecturer have changed the same files, and you then try to pull these changes to update your clone of the repo.
How to handle this depends on what you intend to do with the code:
- I want to make changes to the code and store them in gitlab.
- I want to make changes to the code but only store them locally.
- I want to make changes to the code but not store them.
- I don't want to make changes to the code.
1. Create a separate project with changes
- Fork and clone or directly clone this repo.
- Create your own project that is intended for changes. This can be a repo on gitlab that you clone, or it can be just a local folder if you don't intend on storing it on gitlab.
- Copy over the files you want from your clone of the lecture_code-repo, and paste them into the change-repo. You can push these freely if you created a repo.
- When you want to update your lecture_code repo, use the command
git pull
in your terminal to pull new changes from the lecture_code repo. If you created your own repo, go into this repo on gitlab and press the button that says "Update fork" first. - Copy over the update files you want into your change-repo. You now have no conflicts and get to keep your own changes without problem.
2. Use pull and manually deal with conflicts.
If you want to push your changes to gitlab, use the previous method. This method will make it hard to do so.
The previous method used the command git pull
. No conflicts arose, because no changes had been made to the repo. These were kept in a seperate project. If you don't intend on pushing your changes to git, you can save yourself the trouble of copying files by using git pull
and then manually dealing with the conflicts. When you pull files that cause conflict, you will have to do one of two things first:
Commit or stash
Commiting should be familiar by now. This is what we do before we can push any changes to our gitlab repo.
- If you forked this repo, go into your repo on gitlab and press the button that says "Update fork" first.
- Save all the files you made changes to locally in you IDE.
- Use the command
git add .
in your terminal to "stage" the changes. (Most IDEs have built in functionality to stage changes as well.) - Use the command
git commit -m "YOUR COMMENT HERE"
to commit the changes. DO NOT PUSH. This may cause a lot of issues. If you want to push changes, use the method above. - Use the command
git pull
to get the changes from the cloned repo. Conflicts might arise here, and you have to manually choose if you want to keep one version of the file or both versions.
Stashing means "putting away" you local changes so you can work on other things and then get these changes back when you need them. This method essentially does the same as commiting.
- If you forked this repo, go into your repo on gitlab and press the button that says "Update fork" first.
- Save all files you made changes to locally in you IDE.
- Use the command
git stash
in your terminal to stash away the changes. Your project will revert back to the last commit, and your changes will temporarily disappear. - Use the command
git pull
to get the changes from the cloned repo. - Use the command
git stash pop
to reinstate your local changes. Conflicts might arise here, and you have to manually choose if you want to keep one version of the file or both versions. DO NOT PUSH. This may cause a lot of issues. If you want to push changes, use the method above.
3. Delete the clone and re-clone
If you don't feel the need to keep your changes to the lecture code, you can simply delete your clone whenever new updates are added. Then, you can clone the project over again and take it from there.
4. Don't make changes
If you don't intend on making any changes to the lecture code, but you want to have a local save, there will be no conflict issues and you can just use git pull
in your terminal to update your clone (or use method 3).