avatar
童琦杰
向死而生
githubmusic
2017-01-30编辑

Git简单命令说明

config

git config --local user.name "tongqijie"

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

git config credential.helper store

pull

git pull

push

git push

clone

git clone [remove-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

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 -d [branch] delete branch

git checkout [branch] switch to specified branch

git merge [branch] merge specified branch to current branch