Quick-reference guide for Git processes I use regularly.
To push new changes for a specific branch to the remote repository:
git push origin <branch-name>
To add new changes to your last commit without creating a separate one:
Stage your changes:
git add .
Amend the last commit:
git commit --amend
Edit the commit message in the editor if needed, then save and close.
Or use --no-edit to keep the original message:
git commit --amend --no-edit
<aside> ⭐
Note: If already pushed, force-push with git push --force
(careful if others use the branch).
</aside>
To save the changes introduced by a specific commit to a file:
Run the git diff
command for the commit, redirecting output to a file:
git diff <previous-commit-hash> <commit-hash> > diff_file.patch
Example:
git diff abc1234 def5678 > commit_def5678_diff.patch
<aside> ⭐
Note: Replace <previous-commit-hash>
with the parent commit and <commit-hash>
with the target commit.
</aside>
previous-commit-hash
and commit-hash
in git diff
When using git diff <previous-commit-hash> <commit-hash> > diff_file.patch
, the two commit hashes serve distinct purposes:
previous-commit-hash
: This is the parent commit, representing the repository's state before the changes in the target commit were applied. It acts as the baseline for comparison.commit-hash
: This is the target commit, containing the specific changes you want to review or save.