notes_git
git config –global push.autoSetupRemote true
stash
git stash
is for temporarily storing changes, git add
is for preparing changes for the next commitgit stash list
git stash apply
apply stashed changes to the working directorygit stash pop
apply stashed changes to the working directory and remove that changes from the stash list
to avoid Enter passphrase for key
auto-launching-ssh-agent-on-git-for-windows
rebase
git rebase -i HEAD~<number>
orgit rebase -i <commit number>
for using other commands, just change thepick
word to the command nameedit multiple commit messages
:git rebase -i HEAD~<number>
orgit rebase -i <commit number>
modifypick
toedit
, then save and exitgit commit --amend -m ""
git rebase -continue
to the next commit
insert commit:
run rebase command to the location, and change the commit toedit
whose location is right before the location you want to insert. then you will be at the insert location and able to make a new commit or pick a commit.squash commits
, change commits you want merged tosquash
orfixup(this will discard the commit messages)
. (only consecutive commits can be squashed, while the commits order in editor is changeable)
tag
git tag -d <tag name>
git push origin :refs/tags/<tag name>
git push origin --delete <tag name>
push the delete operation to the remotegit tag -a <tag name> <commit number> -m <tag commit message>
git show <tag name>
to display the tag info along with the commit info
basic
Config user name and email git config --global user.name / user.email “”
git config --list
check git config listpwd show
git init
SSH binding computer ssh-keygen -t rsa -C "your email@example.com"
git config --remove-section gui
reset gui settings
diff
git diff
show all the changes with detailgit diff --name-only
show all the changed file namegit diff --name-status
show only names and status of changed filesgit diff --unified=0
git diff -U0
only show the changed lines
show
show
is used for a certain commit, while log is for getting a history
git show commit number
display the changes of a given commitgit show-branch <branch 1> <branch 2>
log
git log --name-status
show history list with file name and statusgit log -p <file path>
show history list of the given filegit log --follow -p <file path>
show the entire history(including rename ) of the given filegit log -L <start line number>,<end line number>:<file path>
show a history list of the limited lines of the given filegit log <commit number> -L <line number>,<line number>:<file path>
show a history list of the limited lines of the given file of the given commit
git log --all
show all the branch commitsgit log --author=<author name>
show a history list made by the given authorgit fetch --all && git log <origin/branchName>
get the repo state from remote and show the given branch commit historygit status
git log --date=relative|local|default|iso|iso-strict|rfc|short|raw
to change date formats
git log --grep=helloworld
search for commit tipsgit log --pretty=format:"%ad - %an: %s" --after="2016-01-31" --until="2017-03-10" --author=""
to show commits in a specified date rangegit log -S 'helloworld' --source --all
search for commit code
git log -G “^(\s)function foo[(]){$” –source –all
revert && reset
git revert "commit number"
revert
means a new commit which reverts to a given commitgit reset "commit number"
revert to a given commit, and the commits after the given commit will be deletedgit reset HEAD^
git reset --hard origin/feat-windows
setting branch to match remote exactlygit push origin +<commit>:master
revert to a certain commit, and force push to the remote
restore
git restore .
discard local changes
remote
git remote -v
remote listgit remote add/rm origin [repo name]
add or remove a remote repo addressgit remote set-url origin [repo name]
update the existing remote when add a remote that say which already existgit fetch download from remote
push
git add [file] && git commit -a || git commit -m “message”&& git push
git commit --amend -m ""
amend the last commit mesggit push –u origin [branch name]
push local file to remotegit push origin [branch name]
push the last altered file to remote when local made a submitgit push -u origin [branch name] -f
update forciblygit push origin [branch name]
submit the content that altered by branchgit add --patch <filename>
break down the given file into thunks, and choose thunks to commit. input?
to get commands descriptiongit push origin <commit>:<branch name>
push a given commit to a branch
branch
git branch -r --list
git branch -a
all the branchesgit branch --show-current
git branch -m <new name>
alter branch namegit branch -d <name>
delete branch name locallygit branch -D <name>
delete branch name remotelygit clone -b <branch> <remote_repo>
git checkout -b [branch name]
create(if the branch doesn’t exist) and switch to the branch
restore a deleted branch
git reflog
find the last sha of the deleted branch, andgit checkout -b <branch_name> <sha>
get back
checkout
git checkout -d [branch name]
delete a branch locally, so need push to remotegit checkout -D [branch name]
delete a branch locally, to force deleting the branch without checking merged statusgit checkout -b [branch name]
create(if the branch doesn’t exist) and switch to the branchgit checkout [branch name]
switch to a branch onlygit push [repo name] --delete [branch name]
delete a branch both locally and remotelygit checkout .
clean un-staged changes made in the current branchgit checkout <file path>
clean the change of a specific file in the current branchgit checkout <branch name> <file path>
to revert a single file according to branchgit checkout <commit number> <file path>
to revert a file according to previous commitget a file from another branch or another commit and then put it into another path
git checkout <branch name> <file name>
、git checkout <commit num> <file name>
get filegit mv <old file name> <new file name>
copy and movegit reset <old file name>
reset the original file
git push --set-upstream origin [branch name]
To push the current branch and set the remote as upstream
cherry-pick
git cherry-pick <commit -number>
to apply a specific commit to the current branchgit cherry-pick -n <commit -number>
to apply a specific commit to the current branch without commit automaticallygit cherry-pick -v <branch name 1> <branch name 2>
git cherry-pick <commit start>^..<commit end>
pick multiple commits
merge
git merge <branch name or a commit num>
to merge with the given branch or commitgit merge <branch name> --allow-unrelated-histories
to merge two branches no common basesgit merge-base <target branch> <refer branch>
compare the two branches and show the common base
clean
git clean -f
remove untracked filesgit clean -fd
remove untracked directories
pull
git pull --all
fetch
git fetch --all
get all the change of all the branches
config
git config --global gui.encoding utf-8
setgui
encodingas utf-8
Exit editor
press i
to enter insert mode, ESC
(exit the inset mode)
write :WQ
(write & quit) and press enter