Add patch, grep, rebase, and tag commands to git.md

This commit is contained in:
Donovan Glover 2017-11-19 21:10:12 -05:00
parent ccedb86bf7
commit b294e4eea7
No known key found for this signature in database
GPG Key ID: 8FC5F7D90A5D8F4D

View File

@ -16,6 +16,17 @@
- Show the changes that you added but haven't committed yet: `git diff --staged` **OR** `gd --staged` **OR** `gds`
- Show a log of all the commits: `git log` (full log) **OR** `git lg` (commits only, easier to read)
- Edit the last commit message: `git commit --amend`
- Commit a file one part at a time: `git add --patch <file_name>` **OR** `ga --patch <file_name>` **OR** `gap <file_name>`
- Useful when you made a lot of changes to a file and need to commit it
- Enables you to commit certain parts of a file and not the entire thing
- Note that if the file is not in the repository yet, you should do `git add -N <file_name>` or `ga -N <file_name>`
- Go to the next section: `j`
- Go to the previous section: `k`
- Stage this section for the next commit: `y`
- Do not stage this section for the next commit: `n`
- Quit and do not stage this section or any of the remaining sections: `q`
- Split the current section into smaller sections: `s`
- Manually edit the current section: `e`
Note that the `-u` flag means `set-(u)pstream-to`. It records the location so you don't have to set which remote to push or pull from every time.
@ -37,5 +48,25 @@ Also note that `git clone` makes a remote name of `origin` by default. This is w
- Show the differences between your repository and a remote one: `git log -p master..<REMOTE>/master`
- View all remotes for the current repository: `git remote -v` (e.g. GitHub mirror, friend's fork, upstream, etc.)
- Show the entire contents of a commit, including diffs: `git show <commit>`
- Search for a string in the files of a git repository: `git grep <pattern>`
- Search for a string in the files of a git repository: `git grep <pattern>` **OR** `gg <pattern>`
- Search for any tab characters in a repository: `git grep $'\t'` **OR** `ggt`
- Search for any carriage returns in a repository: `git grep $'\r'` **OR** `ggr`
- Merge all unpushed commits into a single commit: `git rebase -i origin/master`
- Note that you are not done after this. You must also change `pick` to `squash` (or `s`) for all of the commits you want to merge. This is usually everything except your most recent commit.
- Another window will open to let you combine all the commit messages into one big commit message
### Working with Tags
- Show all the tags in a repository: `git tag`
- Create a new tag: `git tag -a <tag_name> -m <description>`
- If `-m` is not given, git will open your editor to allow you to type a more detailed message
- The tag name is usually a version number such as `v2.4.3`
- View the saved data of a tag: `git show <tag_name>`
- Tag a specific commit instead of the current state in the repository: `git tag -a <tag_name> <commit>`
- Push a tag to the remote repository: `git push origin <tagname>`
- Note that sharing a tag is the same as sharing remote branches
- Push all tags to upstream: `git push --tags`
- Easily change between versions of a repository (through tags): `git checkout <tag_name>`
- Update a previous version with new changes: `git checkout -b <branch_name> <tag_name>`
- Note that you should make a new tag for the updated commit since `<tag_name>` already refers to a commit and is not changed
- For example, if you checkout tag `2.0` then the new tag can be, for example, `2.0.1` or `2.0a`