avatar
童琦杰
Jan 30, 2017Technology

Git简单命令说明

config

git config --local user.name "tongqijie"

git config --local user.email "tongqijie@hotmail.com"

git config credential.helper store

git config core.ignorecase false: 设置文件名大小写敏感

git config --local --unset user.password

git config --local advice.detachedHead false

git config --local http.sslVerify false

pull

git pull

push

git push

clone

git clone [remote-repository] [local folder]

Chnages

git status

Stage untracked/modified files/folder

git add [file|folder] stage specified single file or specified folder

git add -A stage all changes files

Stash

git stash save "message" store all staged changes.

git stash apply stash@{0} restore

Diff

git diff [file] diff unstaged changes with staged changes

git diff --staged [file] diff staged changes with last commit

Commit

git commit -m [comment] commit with comment

git commit -a commit with unstaged files

Tag

git tag [tag name] set tag

git push --tags push all tags to server

git push [tag name] push a tag to server

Delete

git rm --cached [file] remove single file that has committed

git rm --cached -r [folder] remove all files under folder that have committed

Move/Rename

git mv [old file] [new file]

History

git log --graph --pretty=oneline --name-status

git log --pretty=format:"%h%x09%ad%x09%s" --date=format:'%Y-%m-%d %H:%M:%S' --max-count=10

Undo

git reset HEAD [file] remove staged file

git reset --hard undo changes of modified files

git checkout -- [file] undo unstaged files

git clean -fd remove all untracked files and directories.

Reset

git reset [--soft|--hard|--mixed] [commit id]

  • --soft: HEAD pointer points to specified commit, but working directory does not changes. All changes since specified commit have been staged to commit.

  • --hard: HEAD pointer points to specified commit, and all changes since specified commit will be discarded.

  • --mixed: HEAD pointer points to specified commit, but working directory does not changes. All changes since specified commit are not staged.

Branch

git branch [new branch] create new branch

git branch [new branch] [commit id] create new branch from specified commit

git branch -d [branch] delete branch

git checkout [branch] switch to specified branch

git branch -D [branch] delete local branch

git push origin --delete [branch] delete remote branch

git push origin [branch] push branch to remote server

Merge

git merge [branch] merge specified branch to current branch

git merge --abort abort the merge

Prune

git remote prune origin remove info about removed remote branches

Revert

git revert [commit id] 回滚指定的commit,生成一个新的commit来抵消原来的commit

© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号