These are my personal git notes for my daily life.

git status check file status

git clone RepositoryURL clone a github repository to you local folder.

git add FilePath add the file you name it.

git add . add all files you has modified.

git commit -m "your comment for this commit" commit the changes you have added and add a comment for this change at the same time. (Note: If you miss ‘-m’, it will open a VIM file for you to add comment for this commit after this command)

git pull pull code from remote repository (Note: to avoid overwrite code in remote repository, it is better to use ‘git pull’ before every ‘git push’ )

git push push your local changes to remote repository

git stash save current changes to current branch

git stash list list your stash list in current branch

git stash pop show the latest chage which you stashed

git stash drop drop the latest stashed code in current branch

git stash clear drop all stashed code in current branch

git mergetool open git’s merge tool to handle merge event

gitk show all commit histories, including your local changes

git config --global merge.tool meld set ‘Meld’ as default merge tool

git config --global mergetool.meld.path /filepath/filepath/ set ‘Meld’ file path to default merge tool

git checkout -b NewBranchName RemoteBranchName create a new branch based on a remote branch

Git checkout -b NewBranchName Your SHA1 ID create a new local branch based on a named commit. you can use gitk to check your SHA1 ID

git reset --soft HEAD~1 Delete the most recent commit, keeping the work you’ve done (Note: this command works for commits haven’t push to remote repository, the number show how many local commit you want to reset)

git reset --hard HEAD~1 Delete the most recent commit, destroying the work you’ve done

git branch --all show all branches the repository has, including the branches you never used

git checkout BranchName switch to named branch

git branch -D BranchName delete named branch

git push origin --delete YourRemoteBranchName delete named remote branch

git push -u origin YourLocalBranchName push a local branch to remote repository

git merge BranchName merge branch (Note the BranchName should be the one your want fetch data from and your current branch should be the one you want get more data)

git log -S "KeywordsInTheFile" --source --all --reverse search all file’s commit which contains the keyword you mentioned. The command without --reverse will show the latest one in front.

Any feedback is welcome! :-)

blog comments powered by Disqus