Git Notes
Intro
Notes that describe Git repo creation, usage, maintenance,
The idea is that you can see the commands commonly used to work within command line git and what they do with an actual repository and code....
this is decomposed into two sections. Using gilab / github (our robot code is on gitlab)
Generic Git usage - example based
We use gitlab for our robotics projects: gitlab v github
Our git repo (for obviously the 2019 robot): git@gitlab.mort11.org:programming/2019robot.git
I want to pull and work a branch
- from wherever you want to work: git clone git@gitlab.mort11.org:programming/2019robot.git
- now let's see what we got:
git branch -v -a
lists all repos and check in notes- jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git branch -v -a
drivetrain 72d20ef Added right side to velocity drive master d8175af updated gradle wrapper remotes/origin/EndEffector d6bbc14 Untracked file remotes/origin/HEAD -> origin/master remotes/origin/Vision 688ab76 added automaticCapture remotes/origin/autonomous_chooser 6c4ee16 Completed Shuffleboard Auton Chooser remotes/origin/demo cb68d88 finalized demo and showed it off remotes/origin/drivetrain 72d20ef Added right side to velocity drive remotes/origin/master d8175af updated gradle wrapper remotes/origin/navx 5d45f56 updated TurnDegreesAutomaticTesting CommandGroup with a targetAngle parameter
- We want to switch to drivetrain, so we need set a local branch to track the remote branch (see: tracking)
git branch --track drivetrain orgin/drivetrain
- now you have a local branch, drivetrain, that tracks to the remote/origin/drivetrain
- Ok let's verify that we're all set:
git branch
results in:
jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git branch
* drivetrain
master
- Now that we've been working for some time, you might want to work another branch of code
jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git branch
Vision
auton
autonomous
* autonomous_chooser
drivetrain
ee
master
vision
* Switch to the drivetrain branch by checking it out
jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git checkout drivetrain
Switched to branch 'drivetrain'
Your branch is behind 'origin/drivetrain' by 7 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git pull
Updating 5261bfc..57f3769
Fast-forward
2019robot.ipr | 5 +---
2019robot.iws | 104 +++++++++++++++++++++++++++++++++++-------------------------------
src/main/java/org/mort11/Robot.java | 4 +--
src/main/java/org/mort11/commands/drivetrain/HoldPosition.java | 30 +++++++++++++++++++
src/main/java/org/mort11/commands/drivetrain/MotionMagicTickDrive.java | 3 +-
src/main/java/org/mort11/hardware/IO.java | 5 ++++
src/main/java/org/mort11/subsystems/drivetrain/Drivetrain.java | 17 +++++++----
src/main/java/org/mort11/util/Constants.java | 14 ++++++++-
src/main/java/org/mort11/{commands/drivetrain => util}/Converter.java | 12 ++++----
9 files changed, 125 insertions(+), 69 deletions(-)
create mode 100644 src/main/java/org/mort11/commands/drivetrain/HoldPosition.java
rename src/main/java/org/mort11/{commands/drivetrain => util}/Converter.java (53%)
- This switches branches and pulls code from the remote side.
jerry.olup@dev0105u16:~/work/FRC/git_repos/2019robot$ git status On branch drivetrain Your branch is up-to-date with 'origin/drivetrain'.
And that's how simple it is (once you git it) to work with our remote repository.
For other git actions... like commit, pull, push see below.
Generic Git usage - example based
This is not as critical as the information above but gives you an idea of general git usage. This was something I developed for my team at an old workplace to teach them how to use a git repo I established.
Initialization
Initialize a bare repo (alternative to cloning or pulling). Use git config to check and change your side of the repo. Can set many parameters. A few are shown in the git config section.
After you make changes you should list the changes to view them for accuracy....
git init --bare creates repo in this directory root git config - add tags to data --global user.name "your name" --global user.email jolup@lgsinnovations.com --global core.editor emacs git config --list // check settings git config user.name // return user name
Stage your files
git add <file path from root of repo>
Check status of what's staged
Once staged, you should have "Changes to be committed" with list of new files you may have "Untracked files" listing; this should be empty. Everything in repo should be worthy of tracking. If not, move or destroy the extra files.
EX "git status" returns: # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: components/AHB_bus.vhd # new file: components/AHB_bus_wrapper.vhd # new file: cpld_slave_wave.do # new file: cpld_wave.do # new file: make_ver.tcl # new file: modelsim.ini # new file: run_cpld_simulation.do # new file: src/SataMux_FPGA_01.vhd # new file: src/SataMux_FPGA_01_DEBUG1.vhd # new file: src/cpld_top.vhd # new file: src/cpld_types_pkg.vhd # new file: src/functions_pkg.vhd # new file: src/qspi_slave_ahb.vhd # new file: src/qspi_slave_ahb_r2.vhd # new file: src/qspi_slave_ahb_r3.vhd # new file: src/spi_slave.vhd # new file: src/test_01.vhd # new file: src/types_pkg.vhd # new file: src/version_pkg.vhd # new file: src/wftp_cpld_r0.vhd # new file: tb/AHB_bus_wrapper_sim.vhd # new file: tb/AHB_bus_wrapper_sim_breakout.vhd # new file: tb/SataMux_FPGA_01.vhd # new file: tb/SataMux_FPGA_01_DEBUG1.vhd # new file: tb/clkgen.v # new file: tb/cpld_qspi_tb.v # new file: tb/cpld_tb.v # new file: tb/cpld_tb_non_ahb.v # new file: tb/functions_pkg.vhd # new file: tb/qspi_master_bfm.v # new file: tb/qspi_slave_ahb.vhd # new file: tb/simple_slave.vhd # new file: tb/spi_slave.vhd # new file: tb/test_01.vhd # new file: tb/test_operations.v # new file: tb/types_pkg.vhd # new file: tb/user_logic.vhd # new file: tb/version_pkg.vhd # new file: tb/wftp_cpld_r0.vhd
Now commit files
bash-4.2$ git commit -m 'Initial CPLD project commit' [master (root-commit) bf88314] Initial CPLD project commit 39 files changed, 14089 insertions(+) create mode 100755 components/AHB_bus.vhd create mode 100644 components/AHB_bus_wrapper.vhd create mode 100755 cpld_slave_wave.do create mode 100755 cpld_wave.do create mode 100755 make_ver.tcl create mode 100644 modelsim.ini create mode 100755 run_cpld_simulation.do create mode 100755 src/SataMux_FPGA_01.vhd create mode 100755 src/SataMux_FPGA_01_DEBUG1.vhd create mode 100644 src/cpld_top.vhd create mode 100644 src/cpld_types_pkg.vhd create mode 100755 src/functions_pkg.vhd create mode 100755 src/qspi_slave_ahb.vhd create mode 100755 src/qspi_slave_ahb_r2.vhd create mode 100644 src/qspi_slave_ahb_r3.vhd create mode 100755 src/spi_slave.vhd create mode 100755 src/test_01.vhd create mode 100755 src/types_pkg.vhd create mode 100755 src/version_pkg.vhd create mode 100755 src/wftp_cpld_r0.vhd create mode 100644 tb/AHB_bus_wrapper_sim.vhd create mode 100644 tb/AHB_bus_wrapper_sim_breakout.vhd create mode 100755 tb/SataMux_FPGA_01.vhd create mode 100755 tb/SataMux_FPGA_01_DEBUG1.vhd create mode 100755 tb/clkgen.v create mode 100644 tb/cpld_qspi_tb.v create mode 100755 tb/cpld_tb.v create mode 100755 tb/cpld_tb_non_ahb.v create mode 100755 tb/functions_pkg.vhd create mode 100755 tb/qspi_master_bfm.v create mode 100755 tb/qspi_slave_ahb.vhd create mode 100755 tb/simple_slave.vhd create mode 100755 tb/spi_slave.vhd create mode 100755 tb/test_01.vhd create mode 100755 tb/test_operations.v create mode 100755 tb/types_pkg.vhd create mode 100755 tb/user_logic.vhd create mode 100755 tb/version_pkg.vhd create mode 100755 tb/wftp_cpld_r0.vhd
Having established the repo, clone it to work with it.
From my perspective, on your working laptop:
git clone cpld_git_repo working // checkout the repo to the 'working' directory.
FEW HOURS LATER, (after a bunch of code changes and test) you have a happy point where you should check in code.
So status the repo, then see below to status it with less verbosity. Add the files, commit and push as shown:
Status the working directory
bash-4.2$ cd working bash-4.2$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: cpld_wave.do # modified: tb/cpld_qspi_tb.v # modified: tb/qspi_master_bfm.v # modified: tb/test_operations.v # no changes added to commit (use "git add" and/or "git commit -a")
Once you get used to status, you don't need the verbosity, use -s:
bash-4.2$ git status -s M cpld_wave.do M tb/cpld_qspi_tb.v M tb/qspi_master_bfm.v M tb/test_operations.v
Determine differences between checkout and repo
git diff <file by file, line by line>
Stage files to be committed
bash-4.2$ git add tb/*.v
Verify staging (subtle with the -s status). The indented M is modified file that is not the 'M' files that are not indented (aside from tab) are staged. Add the waveform viewer.
bash-4.2$ git status -s M cpld_wave.do M tb/cpld_qspi_tb.v M tb/qspi_master_bfm.v M tb/test_operations.v
How long form status is (note all are staged now):
bash-4.2$ git add cpld_wave.do bash-4.2$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: cpld_wave.do # modified: tb/cpld_qspi_tb.v # modified: tb/qspi_master_bfm.v # modified: tb/test_operations.v #
Since files are staged you can commit changes.
git commit
A text file comes up, where you can write commit notes. this files is git status just before commit.
bash-4.2$ git commit [master 0c80bfb] Added mode to qspi_master_bfm. Corrected functionality for cpld_qspi_tb. Current functionality includes correct register writes / reads using synthesis-proven top level CPLD code. Testbench (cpld_qspi_tb) verified register read / write. JJO 12.22 4 files changed, 111 insertions(+), 92 deletions(-) rewrite cpld_wave.do (78%)
Now, in working dir, status comes up blank. commit complete.
bash-4.2$ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # (use "git push" to publish your local commits) #
Nothing to commit, working directory clean TBD FORMATTING FOR BELOW SECTION
bash-4.2$ git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 38, done. Delta compression using up to 40 threads. Compressing objects: 100% (26/26), done. Writing objects: 100% (26/26), 30.43 KiB | 0 bytes/s, done. Total 26 (delta 12), reused 0 (delta 0) To /home/jolup/work/wftp/igloo_cpld_design/cpld_git_repo/ af3b682..5d0932d master -> master bash-4.2$ git status # On branch master nothing to commit, working directory clean bash-4.2$
gitk = nice TK interface to view diffs, look at versions based on sha1. In repo root, simply run gitk.
> gitk
You want to revert to an older version? No problem
First, status the repo (working or master)
bash-4.2$ git log --oneline af3b682 01.21.2015 jjo Added debug ports to the top level fpga. committing the design constraints, top level and slave file. The CPLD is reacting d8ac067 jjo 01.20.15 Corrected physical constraints on the QPSI interface. -- changed to LVCMOS33 from TTL -- slowed ske 6494da3 Added non debug design files - forgot to stage these. fb3c3fd Added design files and constraints that capture state of the spi and bus providing them to pins. Added constraints to the repository. Only core is 38b7aa2 Current testbench operation (12.30 commit - 10 AM jjo)x 61a93f5 12.28 jjo - Bugfix in reg_write process, found testing swrst (problem in dummy_cycles) - Added PLL and tested SPI at 60 MHz, CPLD at 80 MHz. cc65a7f Added command processor in qspi_slave. Extended test operations and bfm to verify transaction count, incl verification. Tested command processor (WR 0c80bfb Added mode to qspi_master_bfm. Corrected functionality for cpld_qspi_tb. Current functionality includes correct register writes / reads using synthe bf88314 Initial CPLD project commit
Where you want to create a prior repo copy (can be current working, but why?), clone.
git clone cpld_git_repo/ cpld_git_last_commit
Now revert in the cpld_git_last_commit
git checkout d8ac067
Wrap up
Above was working with local backed up but informal repos. remote repo established on ws-git (gitolite3)
- distribute you pubkey to Pat B
- using git clone gitolite3@ws-git:<REPO> (or whatever your repo is)