git clone <url> [path]git init
git statusgit loggit log --name-status: show filename with modification statusgit log --stat: show filename with more info
git diff <file>git diff <commit_or_branch> <commit_or_branch>git diff -–name-only <commit_or_branch> <commit_or_branch>
git statusfirst, see if you are in troublegit add .to stage all modificationsgit commit -m "<message>"to wrap changes and push the HEAD to new progressgit pushto send changes to the cloud
git pullGrab progress from remote, auto merge when theres changes on localgit pull --rebaseSame asgit pullbut use rebase when theres changes on local
git checkout <path>
git checkout <branch_or_commit>
git checkout -b <new_branch_name>git branch -u <remote>/<new_branch_name> [new_branch_name]to set (bind) the remote branch for push and pull
git remote -v: see the remote registry of the repogit remote add|rm <name> <url>git config ...
git log --oneline --graph --decorate --all
git diff <old_commit_or_branch> <new_commit_or_branch> > my.patchgit apply my.patch
git commit --amend
git checkout <B>to detach head and move to Agit reset --soft <A>to move HEAD to the old commit, but leave the index and working tree as for the commit keptgit commit -C <B>to Redo the commit kept re-using the commit message, but now on top of the old commitgit rebase --onto HEAD <B> <branch_name>to re-apply everything from the olds onwards onto this new placegit push --forceto overwrite remote repo
First the following things need to be defined:
HEAD: thehistory, the current branch is pointing atINDEX/Stage: thecache, the added changesWorking directory: the code and files in your directory
Then
git reset --soft [target]: setHEADonlygit reset [--mixed] [target]: setHEADandINDEXgit reset --hard [target]: setHEAD,INDEXandWorking directorygit checkout <history_node>setHEAD,INDEXandWorking directory, but leaving the original branch- So it is a detached state, you can go back by
git checkout <original_branch> - Or create a branch by
git checkout -b <branch_name>, I foundgit checkout <history_node> -b <branch_name>will do the two steps together
- So it is a detached state, you can go back by
- When cloning a repo from remote, the submodule is not initualized and the submodule directory is empty. To solve this
- add
--recursiveoption when cloning to clone submodules in the target repo, for example:git clone --recursive <url> - use
git submodule initandgit submodule update --recursiveif you already cloned and found that the submodule is empty
- add
git submodule add <url> <path>to add a submodulegit submodule foreach --recursive git pull origin masterto pull the latest code for each submodule- to delete the submodule, it is required to do it manually. Edit
.gitmodulesand.git/configto remove related information and remove the files in working directory
- Code Smart, Don't Code hard by crboy
感恩西瓜,讚嘆西瓜!