Mastering git Lesson 6 - last one Irina Gulina Tomas Tomecek v-t Red Hat How to find things? Course schedule September October s M T W T F S S M T W T F s 1 2 3| 5 6 7 3 4 5 6 7 8 9 8 9 10 [12 13 14 10 11 12 13 14 15 16 15 16 17 j 19 20 21 17 18 19 QÖJ 21 22 23 22 23 24 * 26 27 28 24 25 26 M 28 29 30 29 30 31 November s M T W T F S m 2 3 4 5 6 7 8 9 10 I 11 12 13 14 15 16 17 18 25 19 20 21 22 23 24 26 27 28 29 30 Class N HW 2 3 4 5 6 Bonus Task Deadline 11.10 18.10 25.10 8.11 13.11 13.11 Course grade: November 20 Local troubles Class 4 HW feedback ► Some used rebase, others used rebase i. What is the difference between those two? Will both of them work in a case of HW class 4? Which is easier/ preferable in HW class 4 situation and why? ► Some used push after rebase, others used push —force. What is the difference between those two? ■ Will both of them work? Which is preferable in HW class 4 situation and why? ► merge rebase ► Commit messages 3 4^ Red Hat Local troubles lass 5 HW feedback Questions Any questions or suggestions? 5 4^ Red Hat Today's class ► Git Etiquette or mind your Git manners ► git blame, cherry-pick, submodule ► Efficient git ► Fetching pull/merge requests locally ► Activity in the end ► Let's do a group picture! Git Etiquette or Mind your Git manners 4tRed Hat Commit content • Don't: Two and more changes in one commit 1e4faa0 Fix login timeout BZ, add logout step • Do: One commit = One logical change 1e4faa0 Fix login timeout BZ 2r5asy8 Add logout step Commit content • Separate whitespace changes from code changes, especially unrelated. o Mixing those is a great way to introduce a bug and o Complicates code review 10 4^ Red Hat What is a commit message? • Title/subject line • Body Commit message example $ git log commit Author: Date: Mon Apr 215:10:03 2020-0400 Change how workers are represented Commit Title or Subject line Commit Body * Don't serialize the 'gracefully_shutdown' field * Create a new 'missing' property and serialize it * In the status API, list both online and missing workers Requires PR: https:/^github.com//pull/921 closes #354498 https://bugzilla.redhat.com/show_bug.cgi?id=354498 12 4^ Red Hat What is a "bad" message? $ git log —oneline -5 —author irina —before "Wed Apr 7 2021" dcc2d35 address comments b7aac30 fix issue #123 0b7a4e4 various docs fixes 1e4faa0 ui bug fix fc3d081 readme update d21660dc ToDo 0b7a4e4 Mix fixes and cleanups 5h3d28g refactoring 13 4^ Red Hat What is a "bad" message? $ git log —oneline -8 —author irina —before "Wed Apr 7 2021" dcc2d35 address comments < - what comments? b7aac30 fix issue #123 < - of what project? 0b7a4e4 various docs fixes < - what docs? why? 1e4faa0 ui bug fix < - what was the bug? fc3d081 readme update < - why? d21660dc ToDo < ©©©© 0b7a4e4 Mix fixes and cleanups < -A A ft 5h3d28g refactoring < Uninformative, look-elsewhere commit messages (titles) 14 4^ Red Hat Usage of a commit title • git log — pretty=oneline • git rebase —interactive • merge.summary • gitshortlog • git format-patch, git send-email,... • reflogs • GUI tools for committing and browsing • GitHub, SourceForge, Bitbucket, GitLab,... service 15 4^ Red Hat Poor quality code can be refactored A terrible commit message lasts forever. 16 Red Hat For whom do you write commit messages? 17 Red Hat Why should I write "good7 commit messages? • To help to understand the code change o What has been changed? o Why is that change necessary? • To speed up the reviewing process • To help to locate a bug • To write a good release note or script it 18 4^ Red Hat What constitutes a good commit message? • git commit -m "Fix login timeout bug" • git commit or git commit—verbose Redirect user to the requested page after login https://link/to/issue/tracker 19 4^ Red Hat What constitutes a good commit message? • Capital letter, 50/72, no punctuation in the end $ git commit A brief summary of the commit A paragraph describing what changed and its impact. What constitutes a good commit message? • Present Tense and Imperative Mood cf31dl2 Adds login unit tests 7a9kj4f Fixed login unit tests 101q2wd Update login unit tests Ib7hn61 Removing login unit test "If accepted, this commit will ." Red Hat Conventional / Emoji / Semantic commits Add "keywords and/or emoji to commit message and/or footer based on scope and set of rules. E.g.: feat!: email customers on product changes docs: correct spelling of CHANGELOG feat(lang): add Polish language fix: prevent racing of requests build(Electron): Bump version 7 to 9 Q Improve structure / format of the code (fa Remove code or files %, Fix a bug ±- Critical hotfix Introduce new features §pf Add or update documentation Deploy stuff In Footer: close/closes/closed/fix/fixes/fixed/resolve/resolves/resolved E.g! Fixes: #1 or Fixes #1 CHECK CONTRIBUTING.md like guidance on the project 4^ Red Hat Ticket number in commit messages • Ticketing system != git log o "TICKET-123456 add missing params to class" o "Add missing meta fields to response" □ Takes space in 50 chars limit title □ Look-elsewhere for details message, I'm lazy □ May be not available for interested user or reviewer (permissions, outage) 23 4^ Red Hat What constitutes a good commit message? • Clear Title-What is commit about? • Present Tense and Imperative Mood • No punctuation in a title • Clear Body - What and why is it needed/changed vs how? • 50/72 • Reference to an issue in a body message • Follow the commit convention defined by the team 24 4^ Red Hat 25 4t Red Hat IF YOU DO FORCE PUSH... May the force stay with you. 26 Red Hat Git push —force trap • It's ok to force push to your local branch • It's ok to force push to your (unmerged/open) PR/MR • It's not ok to force push to a public branch 27 4^ Red Hat Git push —force consequences • Lost data • Altered history • Not happy colleagues • Lost karma points How to avoid unwanted force push • Protect important branches • Backup • Use git branch/switch • Use —force-with-lease, carefully • Use PR revert You have a great freedom... to change your history locally. 30 Red Hat Submitting a PR Red Hat Why do we use PR/MR workflow? • Share changes • Get review and feedback • Encourage quality What constitutes a good PR/MR? • Complete piece of work • Adds value in some way • Solid title and body • Clear commit history • Small • Meets project's contribution guidelines Contributors (before submitting a • Follow the repo's conventions • Double check your code (and ToDos) • Add docs • Keep changes small • Separate branch • Be clear and specific • Check your ego and be polite, Open Source Contribution (GitHub) Providerless tag for client go auth plugins #100606 k8S-CJ-robOt merged 1 Commit into kubernetes:«iaster from di»s:providerless-tag-for-cUenc-go-auth-plugins Q 18 hours ago Open with 35 Conversation 9 o- Commits 1 [jj Checks o [t) Hies changed 3 41 dims commented yesterday • edited » Member Q client-go auth plugins are another vector to pull in cloud specific code when they are not needed at all. So ensure that the existing providerless tag is honored. This gets rid of the gcp/openstack/azure built-in auth plugins. /kind bug .'release-note-none What type of PR is this? What this PR does I why we need it: Which issue(s) this PR fixes: Fixes # Special notes for your reviewer: Does this PR introduce a user-facing change? Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: -a- k8s-ci-robot added(^QQH^ffi^^ sizeM needs-triage labels yesterday do-not-merge'release note-label-needed T do-not-merge'needs-kind Reviewers Q wojtek-t ^ xichengliudui Assignees f liggitt area code-organization (elease-btocker release-note-none sig,'apt-machinery sig-'auth size.'M Projects None yet Milestone Labels ■ppravad cncf-cla: yes ^ffl ^% Igtm needs-triage priority/important-soon Linked issues Successfully merging this pull request may close these issues. None yet t- not- merge/needs-stg Red Hat Open Source Contribution (GitLab) 36 ♦ Inkscape > ♦ inkscape > Merge Requests 12946 Merged Created 4 days ago by Viil Jyoti Balodhi Contributor Typo Fixed parent ->parentltem Overview 6 Commits 1 Pipelines 3 Changes 1 All threads resolved Hello, I have fixed a typo in https://gitlab.eom/inkscape/inkscape/-/blob/master/src/selection-chemistry.cpp#L3007-3009 as:- SPItem 'parentltem = dynamic cast(parent); if (parentltem) { // parent was being checked here before rather than parentltem parent transform = parentItem->i2doc affine(); Edited 4 days ago by Jyoti Balodhi Request to merge Jyoti Balodhi: fix fj, into master (2) Merged result pipeline #277765637 passed for 48600ee5 0© A v fl'' Merge request approved. Approved by ^ > $ 0 0 O view e|igib|e approvers (v) Merged by $ Thomas Holder 1 day ago The changes were merged into master with cbfa6879 (J The source branch has been deleted Red Hat Contributors (after submitting a PR/MR) • Check your ego and be polite o @username ping! o @username review please • Ensure your branch merge and tests pass • Use —amend, —fixup or rebase -i • Don't merge your own PR WIP PR/MR • Don't overuse WIP label • Remove WIP label when ready • 'This is ready for review, please." Reviewing a PR 39 4t Red Hat PR Reviewers • Be kind and polite o @username ping, error here! o @username s/foo/bar • Check commit history • Don't fix issues • Ensure the branch can be merged • CI Tests pass • Don't merge WIPs • Squash • Delete branch Questions! We do have questions! 1. What's the difference between plain, - -soft and - -hard reset? 41 Red Hat Questions! We do have questions! 2. What's wrong with this commit title? "aDDED new best functionality in this commmmit: implementing option —foobar." 42 4^ Red Hat Questions! We do have questions! 2. What's wrong with this commit title? "aDDED new best functionality in this commmmit: implementing option —foobar." "Add option -foobar" 43 4^ Red Hat Questions! We do have questions! 3. What's the difference between fetch and Questions! We do have questions! 4. What does push do? 45 4fc Red Hat Questions! We do have questions! 5. What does force push do? More handy commands Red Hat blame git blame display author metadata of lines in a committed file $ git blame README.md 6997al60 (Tomas Tomecek 2023-03-10 11:24:09 +0100 25) ## Lectors 6997al60 (Tomas Tomecek 2023-03-10 11:24:09 +0100 26) * Irina... cb4e8b8b (Tomas Tomecek 2023-05-26 18:56:07 +0200 27) * [Tomas... cb4e8b8b (Tomas Tomecek 2023-05-26 18:56:07 +0200 28) 41c6d3al (Tomas Tomecek 2023-05-29 13:43:00 +0200 29) You can... 41c6d3al (Tomas Tomecek 2023-05-29 13:43:00 + Red Hat blame blame display of author metadata attached to specific committed lines in a file git blame NAME_OF_THE_FILE If we want to know more about the commit, what command we can use? blame git blame display of author metadata attached to specific committed lines in a file git blame NAME_OF_THE_FILE If we want to know more about the commit, what command we can use? git log -p SHA-1 git show SHA-1 blame blame display of author metadata attached to specific committed lines in a file git blame -e NAME_0F_THE_FILE git blame -L startLineNumber,endLineNumber f ilePath git blame -w NAME_0F_THE_FILE 51 4^ Red Hat cherry-pick git cherry-pick Pick a commit by reference and append to the current working HEAD a-b-c-d Main . a-b-c-d-f Main e - f - g Feature -y e - f - g Feature When may it be useful? What is the danger of using it? submodule git submodule allows to keep a git repository as a subdirectory of another git repository S client src Bi common Ü structure.py H helper.py § client_main.py V config I... § .gitmodules 5 server src Jm common gj structure.py § helper.py H server_main.py gj .gitmodules common gj structure.py gj helper.py Source: https://bionicape.com/unreal-pluains-as-ait-submodules/ 4^ Red Hat blame submodule allows to keep a git repository as a subdirectory of another git repository ► When an external component is changing too fast. ► When an external component isn't updated very often ► When a piece of the project is delegated to a third party and you want to integrate their work at a specific time or release. Sometimes, it's the best way to create and manage internal packages or manage changing micro services blame submodule allows to keep a git repository as a subdirectory of another git repository ► Points to a specific commit, not to a ref or branch ► Static, not updated automatically when a host repo is updated submodule git submodule allows to keep a git repository as a subdirectory of another git repository git submodule add URL NAME git submodule add https://gitlab.com/user-name/repo my-submodule .gitsubmodule [submodule "my-submodule"] path = my-submodule url = https://gitlab.com/user-name/repo my-submodule 56 Those are new files on the project and needed to be committed. 4^ Red Hat blame git submodule allows to keep a git repository as a subdirectory of another git repository git submodule init git submodule update git clone —recurse-submodules URL git push ~recurse-submodules=check Questions Continuous Integration (CI) 58 4t Red Hat F main ▼ leapp / .github / workflows / unit-tests.yml vinzenz testing: Start using GH Actions for unit tests (#719) ••• >/ A\ 1 contributor 38 lines (36 sloe) 1.28 KB 1 name: Unit Tests 2 on: push: 4 branches: - main pull_request: branches: - main 9 10 jobs: 11 test: name: Run unit tests in containers 13 runs-on: ubuntu-latest 14 strategy: 15 fail-fast: false 16 matrix: 17 scenarios: - name: Run unit tests with python3.9 on e!8 19 python: python3.9 20 container: ubi8 Why? ► Run tests once a pull request is created or updated ► Run tests once a pull request is merged ► GitHub example —> How? ► GitHub Checks interface Release 0.15.0 #795 ^^^^^^^fc MichaIHe merged 1 commit into oamg:main from pirat89: new-release [□ on Aug 23 Conversation -o- Commits 1 Checks 12 [D Files changed 6 >/| # Release 0.15.0 558d299 ▼ v Unit Tests on: pullrequest Run unit tests in containers (Run unit tests with python3.9 on el8, python3.9, ubi8) succeeded on Aug 23 in lm 43s s/ Run unit tests in containers (Ru... n/ Run unit tests in containers (Ru... > Q Set up job > O Checkout code > O Set main t0 origin/main >✓ Packit-as-a-Service V rpm-build:epel-7-ppc64le •y rpm-build:epel-7-x86_64 V rpm-build:epel-8-x86_64 v Q Run unit tests with python3.9 on el8 1 ►Run script -e -c /bin/bash -c 'TERI* opt=seccomp=unconfined -t leapp-test tests/Containerfile.ubi8 res/contain hooks "Git has a way to fire off custom scripts when certain important actions occur." ► .git/hooks/ ► Client side, Server side hooks 61 4^ Red Hat Source: https://ait-scrn.com/book/en/v2/Customizina-Git-Git-Hooks CI pre-commit ► https://pre-commit.com/ ► Run checks & linters locally ► Fix code before committing ► Run them during the CI process as well packit / packit • #1747 n queued at: 2022-10-19 11:19:09 total time to completion: 29.6s | queue (93ms) | mergeable check (910ms) | clone (735ms) Q ci config (1ms) | pull image (196us) Q build (2.9s) | download (3.2s) ■ run (21.8s) ► Is .git/hooks/pre-commit pyupgrade................................................................Passed black....................................................................passed prettier.................................................................passed check for added large files..............................................passed check python ast.........................................................passed check builtin type constructor use.......................................passed check docstring is first.................................................passed check that executables have shebangs.....................................passed check for merge conflicts................................................Passed check for broken symlinks................................................passed check yaml...............................................................passed detect private key.......................................................passed fix end of files.........................................................Passed mixed line ending........................................................passed trim trailing whitespace.................................................passed f lakes...................................................................passed mypy.....................................................................passed Efficient git Efficient git git aliases ► git config --global --add alias.co commit ► $ cat ~/.gitconfig [alias] co = commit ► git co -m 'this is a commit-' ► less typing \o/ 64 4^ Red Hat Efficient git shell aliases ► $ cat ~/.bashrc # or ~/.your-shell-rc ► alias g=git alias gc=git commit --verbose ► g co -m 'this is a commit-' ► gc -m 'this is also a commit-' ► even less typing \ / W 65 4^ Red Hat blame blame display of author metadata attached to specific committed lines in a file git blame NAME_OF_THE_FILE git who, git history, git praise -> how to add an alias? 4^ Red Hat blame git blame display of author metadata attached to specific committed lines in a file git blame NAME_OF_THE_FILE git who, git history, git praise -> how to add an alias? git conf ig —global alias.history blame git conf ig —global alias.who blame git conf ig —global alias.praise blame 67 4^ Red Hat Efficient git git status in your shell prompt (Fedora) ► [tt@cashew]$ cat ~/.bashrc export GIT_PSl_SHOWDIRTYSTATE=y source /usr/share/git-core/contrib/completion/git-prompt.sh export PSl='[\u@\h \W$(_git_psl " (%s)")]\$ ' ► [tt@cashew git-repo (oct-copr-storage-move *)]$ vim README.md ► no typing \ / \ / \o/ 68 4^ Red Hat Efficient git Text-mode interface for git ► $ tig ► https://aithub.com/jonas/tia ► git log, git add, git branch -a, git blame on steroids 69 4^ Red Hat Efficient git Check out a pull request locally (why) ► Why? Review the code locally Try the code Cherry-pick commits 70 4^ Red Hat Efficient git Check out a pull request locally (how) fetch all by default ► $ cat ~/.gitconfig [remote "upstream"] fetch = +refs/pull/*/head:refs/remotes/upstream/pr/* fetch = +refs/merge-requests/*/head:refs/remotes/upstream/mr/* ► git fetch origin pull/ID/head:BRANCHJMAME git fetch origin pull/978/head:my_branch git switch my_branch fetch only one 71 4^ Red Hat Efficient git Git Internals - Plumbing and Porcelain 4^ §lt --fast-version-control Search entire site. 72 About Documentation Reference Book Videos External Links Downloads Community This book is available in English. Full translation available in azarbaycan dili, 6-bjirapcKH e3HK, Deutsch, httDs://ait-scm.com/book/en/v2/Git-lnternals-Plumbina-and-Porcelain Chapters ▼ 2nd Edition 10.1 Git Internals - Plumbing and Porcelain You may have skipped to this chapter from a much earlier chapter, or you may have gotten here after sequentially reading the entire book up to this point —in either case, this is where we'll go over the inner workings and implementation of Git. We found that understanding this information was fundamentally important to appreciating how useful and powerful Git is, but others have argued to us that it can be confusing and unnecessarily complex for beginners. Thus, we've made this discussion the last chapter in the book so you could read it early or later in your learning process. We leave it up to you to decide. Now that you're here, let's get started. First, if it isn't yet clear, Git is fundamentally a content-addressable filesystem with a VCS user interface written on top of it. You'll learn more about what this means in a bit. Red Hat Efficient git git rebase my-branch^internals ► All changes made by commits in the current branch but that are not in are saved to a temporary area. This is the same set of commits that would be shown by git log . .HEAD; ► The current branch is reset to . This has the exact same effect as git reset --hard . 0RIG_HEAD is set to point at the tip of the branch before the reset. ► The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order. Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD.. are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped). ► It is possible that a merge failure will prevent this process from being completely automatic. You will have to resolve any such merge failure and run git rebase --continue. Another option is to bypass the commit that caused the merge failure with git rebase --skip. To check out the original and remove the .git/rebase-apply working files, use the command git rebase --abort instead. ► MUCH MORE INFO IN THE git-rebase MANPAGE 4^ Red Hat httDs://ait-scm.com/docs/ait-rebase git Issues git issues a lightweight issue-tracking system that is available in all repositories Q ansible / ansible Public <> Code O Issues 663 J*j Pull requests 332 0 Actions ffj Projects 14 Q Security Insights Filters - Q isiissue is:open Watch 2k - ^ r<> Labels 602 cj= Milestones 3 Q 663 Open -y 30,212 Closed Author- Label- Projects - Milestones - Assignee - Sort- O apt module with cache valid time does not update when cache was never updated before affects. 213 bug gig^ P3 #79206 opened 17 hours ago by tumbl3w33d • P3 O Update endoflife.date attects_2.i5 fSaOQ oneiroid #79190 opened 4 days ago by mariolenz o 1,asl( bone • CP2 Link to meetup page on community page on docsite is 404 affects.2.15 fiSBEfr OP #79188 opened 4 days ago by lelixfontein 01tasK bone O Unable to install collection with type: git affects 2.13 bug ^Jj^ P3 #79168 opened 6 days ago by kennedyjosh 0 1 task d°ne en O Documentation about required installed tools on the remote host? affects_2ts ^[^LfctiMJtlA #79f46 opened 10daysagobyKoenDG O 1 task done 111 O Unexpected exception while installing collections from requirements.yml file affects..2.13 bug tracet-ack #79109 ooened 14 davs aao bv kennedviosh r\ 1 task done 111 - Red Hat issues a lightweight issue-tracking system that is available in all repositories ► Small? Go defaults ► More traffic? Introduce templates, labels Avoid duplicates Add structure, be specific ► Vulnerability reports ► Triage and close issues Labels By responsibility Non triages Need Info HelpWanted Mention people ■ Assign ^ Red Hat git issues g ansible/ansible puwic <3> Watch 2k » ^ <> Code © Issues 663 J1 Pull requests 332 © Actions __ Projects 14 Q Security __ Insights \ Bug report Create a report to help us improve O Documentation Report Ask us about docs Feature request Suggest an idea for this project Report a security vulnerability Please review our security policy for more details View policy ? Security bug report & Please learn how to report security vulnerabilities here. For all security related bugs, email security@ansible.com instead of using this issue tracker and you will receive C3 Open a prompt response. For more information, see https://docs.ansible.com/ansible/latest/community/reporting_bugs_and_features.html V Ansible Code of Conduct » Be nice to other members of the community. ® Behave. B Open Red Hat Lab ► https://aitlab.eom/redhat/research/masterina-ait/Vblob/m 78 4t Red Hat Class 6 homework https://aitlab.com/redhat/research/masterina-ait#class-6-homew^ Questions to answer 1. How many commits were merged into main between September 1st and October 30th 2023? 2. Who authored commit "Merge branch 'hw03' into 'main'" and what is the commit body? 3. Find one commit that you think should have better title or body and tell us how and why? If you are the author, that's amazing :) 4. Show us a commit that DID NOT change README.md in the month of September? 5. How many unique contributors the repository has at October 31st? 6. How many commits differ between main and main-oct-9? 7. Which commit added this line? **Grading**: successfully complete 5 mandatory homeworks., or 4/5 homeworks plus a bonus task 79 4^ Red Hat Class 6 homework ► Push a single commit with answers in your fork of mastering-git in a text file < UCO > .txt in class6_homework/ directory in a branch named class6-homework ► No MR ► For every question, send us all commands you ran to find out the answer. ► The file syntax: # Question 1 command 1 command 2 Answer/Text comment # Question 2 command 2 Answer 80 Question 3 4^ Red Hat Questions! Beer/Lemonade with the teachers ► Make a group Picture ► Today ► 18:00 ► U drevaka 81 Red Hat