Arvutiteaduse instituut
  1. Kursused
  2. 2018/19 sügis
  3. Objektorienteeritud programmeerimine (LTAT.03.003)
EN
Logi sisse

Objektorienteeritud programmeerimine 2018/19 sügis

  • Kodutööd ja praktikumid
  • Loengud
  • Kursuse korraldus
  • IDE juhendid
  • Silumisest
  • Edasijõudnute rühm

A tiny exercise in git

  1. Install git
  2. Create a github.com account
  3. Create a new hello world project in IDEA (main class sout("hello world"))
  4. See if git --help works. See if git commit --help works. Should work for all commands.
  5. Move the command line to your project root cd "/path/to/repo"
  6. Start a git repo in project root with git init
  7. We don’t want to version control IDE files and compiled code. Add a .gitignore file to your repo root with the following lines:
    .idea
    *.iml
    out
  8. Commit only .gitignore
    1. Add .gitignore to staging git add .gitignore
    2. Use git status to verify no other files are staged
    3. Commit git commit -m "added gitignore"
  9. Commit all other files
    1. Add files git add .
    2. Make sure ignored files are not staged git status
    3. Commit git commit -m "added code"
  10. Use git log to see what’s up git log
  11. Change "hello world" to "goodbye world", commit git add . + git commit -m "goodbye"
  12. Use git log to see what’s up git log
  13. Create a repo in github
  14. Push your project to github repo
    1. Add the github remote to your project git remote add origin <repo url>
      A remote is basically an alias for some repo url
    2. Push to your github repo git push origin master
      Here origin is the repo alias, master is the branch name
    3. Visit github to verify the files are there
  15. Add your friend as a contributor to your project ((s)he’ll need edit permissions)
  16. Have your friend change your code
    1. Let him git clone <github repo url>
      This will create a local copy of the repo from github. NB! don't clone a repo into another repo - run cd .. before or move whereever you want the repo cloned to.
    2. Let him change "goodbye world" to "friend was here"
    3. Let him commit and push (remote origin is already added by clone command)
    4. Ensure his change is visible in github
  17. Pull the changes to your local repo git pull origin master
    If you get tired of writing out origin master, use git branch --set-upstream-to=origin/master master
  18. Change "friend was here" to "hello conflict", commit, don’t push
  19. Have your friend change "friend was here" to "friend still here", commit, push
  20. Pull changes from github. Different people have changed the same lines, so you now have a merge conflict: CONFLICT (content): Merge conflict in src/Hello.java. Yay!
  21. Let's get some help from IDEA
    1. Open your main class. You'll see some conflict markers >>>>>>>, ======= etc.
    2. From VCS menu "Enable version control integration" -> git
    3. Use VCS -> Git -> Resolve conflicts
    4. Select your main class and click the MERGE button
    5. The three-way-merge editor will show you your old code, your friend's code and the result in the middle. Tweak the middle code so you're happy with the result, then click Apply.
    6. Merge all the files if you have more. Trivial changes are merged automatically.
    7. Make sure there were no mistakes. Use Build -> Rebuild project and see if it passes.
  22. Now the code is merged and good to go. See git status and make sure git says "All conflicts fixed". Use git add to add more files if needed. Commit the merged code.
  23. Check git log --oneline --graph to see what's up
  24. Delete your main class
  25. Whoops, why did you do that?! We still need that. In case of major screw ups, run git reset --hard HEAD. THIS WILL DELETE ALL UNCOMMITED CHANGES and revert back to the last commited state. Try it now. Main should be back.
  26. Let's go back in time
    1. If you have any uncommited changes, use git stash to stash them away
    2. Use git log to find the first commit's id (the big long hash thingy)
    3. Use git checkout <commit id>
      Yay, our old code! Take a moment to admire it in IDEA
    4. To go back to the latest commit git checkout master
    5. Restore your stashed changes git stash pop
  27. If you mess up a merge, delete all your code and delete your branches, then git reflog might save your ass. Hope you won't need it any time soon.
  28. Remember all this stuff for your group project
  29. Read about git interactive rebase at home
  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused