Intermediate Git
George Boorman
Curriculum Manager, DataCamp
Command | Function |
---|---|
git diff |
Show changes between all unstaged files and the latest commit |
git diff report.md |
Show changes between an unstaged file and the latest commit |
git diff --staged |
Show changes between all staged files and the latest commit |
git diff --staged report.md |
Show changes between a staged file and the latest commit |
git diff 35f4b4d 186398f |
Show changes between two commits using hashes |
git diff HEAD~1 HEAD~2 |
Show changes between two commits using HEAD instead of commit hashes |
git diff main summary-statistics
space
to progress through and q
to exitgit branch
main
* feature_dev
feature_dev
Need another branch for a second new feature being developed
Solution - rename feature_dev
Renaming a branch
git branch -m
git branch
main
* feature_dev
feature_dev
Need another branch for a second new feature being developed
Solution - rename feature_dev
git branch -m feature_dev chatbot
git branch
main
* chatbot
Large projects can have many branches
Delete branches once we are finished with them
Delete the chatbot
branch with -d
flag
git branch -d chatbot
Deleted branch chatbot (was 3edb989).
chatbot
hasn't been merged to main
, git branch -d chatbot
will produce an errorerror: The branch 'chatbot' is not fully merged.
If you are sure you want to delete it, run 'git branch -D chatbot'.
-D
flaggit branch -D chatbot
Deleted branch chatbot (was 3edb989).
Difficult, but not impossible, to recover deleted branches
Be sure we don't need the branch any more before deleting!
Command | Function |
---|---|
git diff main chatbot |
Compare the state of the main and chatbot branches |
git branch |
List all branches |
git branch -m old_name new_name |
Rename branch called old_name to new_name |
git branch -d chatbot |
Delete chatbot branch, which has been merged |
git branch -D chatbot |
Delete chatbot branch, which has not been merged |
Intermediate Git