Introduction
Git is maybe the best control version software. At present, Git has been the most used in managing source codes and responsible for everything happens locally on your computer. Therefore, I bring to you this post showing the most useful commands to make your work more easier. Enjoy it and share with other developers.
Check the status of the current branch, list the files changed and need to add or commit:
git status
List all the branches, and also tell you what branch your're currently in:
git branch
See diff of what is changed but not added:
git diff
See diff of what is staged but not yet committed:
git diff --cached
See recent commit history:
git log
See commit history for the last two commits:
git log -2
See commit history for the last two commits, with diff:
git log -p -2
See commit history printed in single lines:
git log --pretty=oneline
See differences between two commits:
git diff commit1_id commit2_id
See the files changed between two commits:
git diff --name-only commit1_id commit2_id
See diff before push:
git diff --cached origin/master
See details of your change of a commit:
git show commit_id
Make some changes, commit them
git add changed_file.txt
git commit -m "Commiting changes"
Rename, move and remove files:
git rm remove_file.txt tmp/crap.txt
git mv old_name.txt new_name.txt
git commit -m "remove and move some files"
Change message of last commit:
git commit --amend -m "New commit message"
Push local commits to remote branch:
git push origin branch name
See recent commit history
git log
See commit history for the last two commits
git log -2
See commit history for the last two commits, with diff
git log -p -2
See commit history printed in single lines
git log --pretty=oneline
Undo last commit, preserving local changes
git reset --soft HEAD~1
Reset to remote state
git fetch origin
git reset --hard origin/master
Create a branch
git checkout master
git branch branch_name
Checkout a branch
git checkout branch_name
See commit history for just the current branch
git cherry -v master
(master
is the branch you want to compare)
master
is the branch you want to compare)
0 Comments:
Post a Comment