Git
Commit Management
Juraj Oravec
Slovak University of Technology in Bratislava
Git – basic workflow
Remote repository
Local repository (.git/)
Staging area (index)
Git – basic workflow
Remote repository
Local repository (.git/)
Staging area (index)
Git – recall: summary
git status
git add filename
git rm filename
git clean -d -i
git reset filename
git checkout filename
Git – basic workflow
Remote repository
Local repository (.git/)
Staging area (index)
Git – hash of commit
hash is a unique identifier of each commit
hash is a hexadecimal (HEX) number calculated using parent node’s unique identifier and the difference between the new version
and its parent node
Git – committing new changeset
git commit –m “message”Git – committing message
git commit –m “type[scope]: description”
type:
– bugfix – fix a bug (patch): ver. 1.0.0 → 1.0.1
– minor – minor change (feature): ver. 1.0.0 → 1.1.0
– major – major change (breaking change) : ver. 1.0.0 → 2.0.0 – docs – change/update in documentation (readme)
– refactor – code changes focused on improving its readability
scope (optional): specify what has changed (preferably in 1 word)
Git – advanced committing tools
git commit --file=filenamecommits new changeset with message given in filename
git commit --dry-run
summarizes what is going to be committed
git commit --dry-run --short git commit -n --short
Git – pushing commits
git push
pushes commits from local repository to remote repository
git push –f
git push --force
forces push ignoring (deleting!) conflict commits (rewrites history!)
git push –u origin master
Git – commit logs
git log
show log of all commits
Git – checking difference
git diff HEX1 HEX2
compares the differences between commits pointed by HEX1 and HEX2
git diff HEX1 HEX2 --name-status
Git – fake commit information
git commit –m “info” --author=‘name <[email protected]>’ commits new changeset as author name
git commit –m “info” --date=‘date time’ commits new changeset logging override date date
Date and time format: YYYY.MM.DD HH:MM MM/DD/YYYY HH:MM
Git – commit bugfixing
git commit --amend –m “message”
replaces (deletes!) tip commit by new commit with new message
git commit --amend --no-edit
replaces (deletes!) tip commit by new commit with old message
Note:
Forced push is necessary, if the original changeset was already pushed! Meanwhile, the original changeset could be pulled by other user!
Git – commit bugfixing
Git – tagging commit
tag is a pointer to a specific commit just before a tag was created
git tag git tag –l
git tag --list list tags
Note:
Git – removing tag
Git – forcing tag
git tag “tag” --force overrides the non-unique tag
Git – pushing and pulling tags
git push --tagspushes commits up to the last tags
git push origin “tag”
pushes to remote URL origin all commits up to commit tagged by “tag” (including)
Git – commit logs
git log
show log of all commits
git log --graph
Git – selecting sequence of logs
git log –numbershows last number logs
git log HEX1..HEX2
shows logs from hash HEX1 to HEX2
git log HEX1..HEAD
shows logs from hash HEX1 to HEAD
git log HEX1..master
Git – selecting logs by date
git log --since=“YYYY-MM-DD”
show logs since date year YYYY, month MM, day DD
git log --until=“YYYY-MM-DD”
Git – searching for logs by pattern
git log --author=usershows just commits of selected user
Git – searching for logs by commit changes
git log –G‘RegExpString’finds commits which modified a line that mentions a particular string (finds commits having the blob including the string)
String can be defined using regular expression format
git log –I‘RegExpString’
Git – logging formats
git log --pretty=format show log of commits in set format:
oneline – dense 1-line (SHA, branch, message) short – shortened (SHA, branch, author, message) medium – default (SHA, branch, author, date, message)
full – full (SHA, branch, author, commit, message)
fuller – fuller (SHA, branch, author, date, commit, commit-date, message) raw – raw (SHAs: commit, tree, parent; author, committer, message)
Note:
Git – summarized logs
git shortlog
sorts logs of commits by authors
git shortlog –c
git shortlog --committer
sorts logs of commits by committers (not authors)
git shortlog -s
Git – summarized logs
git shortlog –e
git shortlog --email
sorts logs of commits including e-mail addresses
git shortlog --after=DATE
sorts logs of commits more recent than DATE
Git – fetching commits
git fetch
downloads changesets from remote repository to local repository
git fetch --dry-run
shows what would be done without any changes
git fetch -f
Git – checkouting commits
git checkoutupdates/restores files in current directory from staging area or switches between branches
git checkout -- filename
discards (delete) changes in working directory by reloading file
Git – checkouting to a specific commit
git checkout tagupdates files in current directory by commit tagged by tag
git checkout HEX
updates files by commit identified by hexadecimal identifier HEX
git checkout master
Git – pulling commits
git pull
git pull –ff
downloads and updates changes from remote repository to local repository (git pull = git fetch + git merge)
– fast-forward: merging does not create commit (default)
git pull --no-ff
Git – tagging commit
Git – basic workflow
Uploading changes: Downloading changes:
git add . git pull
git commit –m “…” git merge
git pull
git merge
Git – summary
git commit -m “message” git tag tag
Git – summary
Remote repository
Local repository (.git/)
Staging area (index)
Git – outlook: project from git basics
Remote repositoryLocal repository (.git/)
Staging area (index)