book-git-commands/src/commits.md

109 lines
2.7 KiB
Markdown
Raw Normal View History

# Commits
```bash
2018-08-17 20:05:41 +00:00
# Use a basic GUI. Actually works quite well for staging hunks that can't be split.
git gui
# See what has changed/etcetera
git status
# See how many files have changed (insertions/deletions)
git diff --stat | tail -n1
# See what or how many files are staged.
git diff --cached --stat
git diff --cached --stat | tail -n1
# Difference. Use Shift + Q to quit.
git diff <file>
# Difference, ignoring space changes (EOL and multiple into one).
git diff -b <file>
# See what changed in a file that's already been staged.
git diff --cached <file>
# Add/stage a new/updated file.
git add <file>
# Add/stage multiple files, space delimited
git add <file> <file>
# Add a file with prompts on what to do with hunks
git add <file> -p
git add <file> --patch
2018-02-05 03:08:14 +00:00
# Add/stage all changes with prompts on what to do with hunks.
git add -p
# Add/stage all changes (including deletions)
git add -u
# Add/stage file deletion.
git rm <file>
# Add/stage file move/rename (such as case sensitive change)
git mv -f <file> <File>
# Add/stage directory rename.
git mv <oldDirectoryName> <newDirectoryName>
# Unstage change.
git reset HEAD <file>
# Unstage all changes.
git reset
# Selectively unstage changes to files.
git reset -p
# Work in Interactive mode.
git add -i
# Discard changes to a file
git checkout -- <file>
# Selectively discard changes to a file
git checkout -p
# Get a file from a particular commit.
git checkout a1b2c3 -- <file>
# Get a file from the commit previous to the commit. Helpful if you want to revert a change just made to a file.
git checkout a1b2c3~1 -- <file>
# Commit with Message.
git commit -m "Message"
# Commit with a summary and detail. Additional -m parameters can be passed as needed.
git commit -m "Summary" -m "Details"
# Update the last commit's message.
git commit --amend -m "Message"
# Update the last commit's date (reflected on GitHub).
git commit --amend --no-edit --date="Fri Nov 6 20:00:00 2016 -0600"
# Add another file to the last commit. Uses the last message.
git add <file>
git commit --amend -C HEAD
# Add all changed files and commit. New files are not committed.
git commit -am "Message"
# Show changes made in a particular commit.
git show <commit_id>
# Show the message and files from a particular commit.
git show --stat <commit_id>
2019-05-29 14:12:28 +00:00
# See a list of files that have changed in the current branch, compared to master. Includes number of files and inserts/deletes.
git diff --stat master...
git diff --stat master...<branchName>
# See the number of changed files, and how many inserts/deletes there were in a branch, since master.
git diff --shortstat master...<branchName>
# See a list of just the file names that were changed in a branch, since master.
git diff --name-status master...<branchName>
```