Arvutiteaduse instituut
  1. Kursused
  2. 2024/25 kevad
  3. Objektorienteeritud programmeerimine (LTAT.03.003)
EN
Logi sisse

Objektorienteeritud programmeerimine 2024/25 kevad

  • Kodutööd ja praktikumid
  • Loengud
  • Kursuse korraldus
  • IDE juhend
  • Süvendusrühm
  • Silumisest

A tiny exercise in git

  1. Read https://guides.github.com/introduction/git-handbook/
  2. Install git
  3. Create a github.com account
  4. Create a new hello world project in IDEA
  5. Open the command line. See if git --help works. See if git commit --help works. Help exists for all commands.
  6. Navigate to your project root cd "/path/to/project"
  7. Start a git repo in project root with git init
  8. We don’t want to version control IDE files and compiled code. Add a .gitignore file to your repo root with this content
  9. Commit only .gitignore
    1. Include .gitignore in the next commit git add .gitignore
    2. Use git status to verify no other files are staged
    3. Make a commit git commit -m "added gitignore"
  10. Commit all other files
    1. Include all files in the next commit git add .
    2. Make sure ignored files are not staged git status
    3. Make a commit git commit -m "added code"
  11. Use git log to see the history git log
  12. Change the code to print "goodbye world" instead of "hello world". Commit the change: git add . + git commit -m "goodbye"
  13. Use git log to verify the commit was created
  14. Create a new public repository in github
  15. Push your project to the new github repository
    1. Add the github remote to your project git remote add origin <repo url>. A remote is basically an alias for a repository url.
    2. Push your commits to the github repository git push origin master. Here origin is the repo alias and master is the branch name.
    3. Visit github to verify that the files are there
  16. Add a friend as a collaborator to your project. If you have no friends, ask the instructor to fill in 🐧
  17. Have the friend change your code:
    1. Clone the repository with git clone <github repo url>
      This will pull a copy of the repo from github and store it locally. Don't run the clone command inside another repository directory.
    2. Change "goodbye world" to "friend was here"
    3. Commit and push (remote is already configured by clone command)
    4. Ensure the change is visible in github
  18. Pull the changes to your local repo git pull origin master
  19. Change "friend was here" to "hello conflict". Commit the change, but don’t push yet.
  20. Have the friend make another change: change "friend was here" to "friend still here", commit and push.
  21. Pull changes from github again. Since different people have changed the same lines, git will be unable to automatically merge the changes. This is called a merge conflict. The pull will show CONFLICT (content): Merge conflict in src/Hello.java.
  22. 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.
  23. 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 and push it. Verify that it's in github.
  24. Check git log --oneline --graph to see what's up
  25. Delete your main class
  26. 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.
  27. 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 string of random characters)
    3. Use git checkout <commit id>. This will restore the 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 (if any) with git stash pop
  28. 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.
  29. Remember all this stuff for your group project
  30. Read about git interactive rebase if you're bored.
  • 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