-
Notifications
You must be signed in to change notification settings - Fork 1
Chapter_2
Chris McIntosh edited this page Nov 19, 2019
·
1 revision
-
git initwill turn a project into a git repository - creates the
.gitsubdirectory -
git addadds files to be tracked by git -
git clonepulls down all the repo data from the server- can be used to restore a server in the worst case
- Git can use http(s) or git protocols
- git protocol uses SSH
- Tracked files are all that git knows about
- UnTracked files are everything else in the staging area
-
git statuschecks the status of each file in the repo -
git addbegins tracking the new file(s)- new files are staged
- Once files are modified they will be in the changed but not staged section of the status
- A specific version of a file is staged, so it can be both staged and un-staged at different versions if you make changes to a file after staging it but before commiting the stage
-
git status --shortis a shortform status- Two columns, staging and working directory
- A means added, M modified, ?? Means untracked file
-
.gitignoretells git what files to ignore. Won't show up as untracked- Blank lines or # lines are ignored
- Glob's work
- start a line with
/to avoid recursing - end line with
/to specify directories - Negate a pattern with
! - file follows a heirarchy like the
.gitconfigfile
-
git diffshows the current diff of the modified changes against the stage (or last commit if the stage is empty) -
git diff --stagedshows the diff of the staged changes against the last commit -
git commitcommits your stage and lets you view the changes and create a commit message -
git commit -mallows you to specify the commit message on the CLI -
git commit -aautomatically stages all tracked files with changes before commiting- Allows you to skip the
git addstep if desired
- Allows you to skip the
-
git rmremoves a files from filesystem and git tracking - 'git rm --cached
removes file from staging area but not working tree (so we can keep it locally but likely add it to.gitignore`) -
git mvmoves and renames files
-
git logshows commits in reverse chronological order -
git log --patchshows the changes in the commit -
git log -<n>limits the output to the last N commits -
git log --statshows abbreviated stats for each commit -
git log --pretty=<format>allows you to specify commit format for parsing in scripts -
git log --graphshows a graph of merge history, useful with--pretty -
git log --since=<time period>limits to commits since time period- Can be a real date or a relative date like "2 years ago"
-
git log --until=<time period>as above only commits until the time period -
git log --author=<author>limits commits to certain authors -
git log --grep=<grep string>lets you search commit messages -
git log -S <string>lets you search for commits that changed the number of occurences of that string (usually a function) -
git log <options> -- <path>lets you limit your search for commits to a subdirectory
- Undoing is dangerous, sometimes irreversable
-
git commit --ammendlets you change a commit -
git reset HEAD <file>unstages a staged file -
git checkout -- <file>throws away working directory changes - Most things can be recovered, but nothing can be recovered if it never made it into a commit
-
git remote -vshows remotes with url's - lets you pull (and sometimes push) with many different collaborators
-
git remote add <name> <url>lets you add a remote for fetch and push -
git fetch <remote>gets the data from a remote -
git fetchonly downloads the remote data into your local repo, it doesn't merge it -
git pulldoes a fetch and a merge -
git push <remote> branchpushes your changes up to remote -
git remote show <remote>shows you info about the remote -
git remote rename <remote> <new name>renames a remote -
git remote rm <remote>removes a remote
-
git taglists tags -
git tag -l <string>searchs for tags - tag types
- lightweight, basically just a branch pointing at a specific commit that can't change
- annotated ** full objects in database ** contain tagger name, email, date, and message ** recommended way to tag things
-
git tag -a <tag name> -m <tag message>tags the current commit as an annotated tag -
git show <tag name>shows the tag info -
git tag <tag name>creates a lightweight tag-
git showwill only show the commit that is referenced the LW tag
-
-
git tag -a <tag name> <commit sha1>tags the specified commit - tags are not pushed to master automatically
-
git push <remote> <tag name>pushes the specified tag to the specified remote -
git push <remote> --tagspush all tags to remote -
git tag -d <tag name>delete the specifed tag -
git push <remote> :refs/tags/<tag name>push null (before the colon) to the remote tag name, deleting it -
git push <remote> --delete <tag name>delete the tag on the remote -
git checkout <tag name>checkout the tag in a detached HEAD state- A state that is not on a branch
- If you make a commit it lives nowhere but your local repo and can't be pushed
-
git checkout -b <branch> <tag name>checkout the tag to a new branch so you can make and push changes if desired
-
git config --global alias.<alias name> <command>creates the alias for the specified command - Run non git commands with a preceding
!IE:git config --global alias.visual '!gitk'
- Useful commands
git add <file|directory>git clone <remote URL>git statusgit status --shortgit diffgit diff --stagedgit commit -m <message>git commit -am <message>git rmgit rm --cachedgit loggit log --patchgit log -<n>git log --statgit log --pretty=<format>git log --graphgit log --since=<time period>git log --author=<author>git log --grep=<grep string>git log -S <string>git log <options> -- <path>git commit --ammendgit reset HEAD <file>git checkout -- <file>git remote -vgit fetch <remote>git pullgit push <remote>git remote show <remote>git taggit tag -l <string>git tag -a <tag name> -m <message>git push <remote> <tag name>git push --tags <remote>git tag -d <tag name>git push <remote> --delete <tag name>git config --global alias.<alias name> <command>