Git Commands Flashcards
git log
Displays all the commits, history along with commit hash, who committed and the date and time of commit
git log –oneline
Just shows commit hash and commit message
git log –name-only
Shows git log information with list of files that were changed in that commit
git log –author=’max’
list commits only from this author max
git log -1
only list the last commit, the most latest one
git checkout -b sarah
Create a new branch and checkout to that branch
git checkout sarah
switch to an existing branch
git branch -d max
To delete a branch
git branch
Command to list all branches
What is HEAD in git repository?
HEAD is where you are right now in the git reposito
git log –graph –decorate
to see the graphical view of how the branches were created like from which branch to which branch
git remote add origin http://git.example.com/sarah/story-blog.git
To add a remote repository for a local repository
git push origin master
to push your local repository changes to the origin which is your remote repository
git pull origin master
git fetch origin master
git merge origin/master
get rebase master
If you are working in a branch and want to merge with master but if by that time the master branch had also been updated, we can rebase the master
git rebase -i HEAD~4
Interactively rebase last 4 commits
git command to rebase last 4 commits. Like keep the first commit and merge the 3 after commits to the first one
Change the word to squash
git cherry-pick <commit></commit>
git reset –soft HEAD~1
reset but still keep the changes that were made
1 is the number of commits you want to reset
git revert <commit></commit>
git reset –hard HEAD~1
hard option to lose the chnages that were made on that commit
1 is the number of commits you want to reset
git stash
to stash changes within a branch temporarily