git add . Stage all changes from the currentdirectory (and below)
git add –I Interactively stagechanges
git add –A Stage all changes including new files and deleted files
git add -u Stage all file modifications (not new files) from the root of the repository
git commit Commit all changes previously staged
gitcommit -m Specifya commit message on the command line
git commit -a Commit all previously staged changes and stage alladditional file modifications (not new files)
git commit <file(s)> Commit onlythe specified <file(s)>, ignoring what is in the index. This is called a “partial commit”
git log Shows the ancestryof the current HEAD
git log –n Shows the last n commits of the ancestry of HEAD
git log < path > Shows the commits in the ancestry of HEAD which modified < path > in some way
git log --since=“2 weeks ago” Show all commits from the last two weekswhich are considered ancestors of HEAD
git log --branches < branch1 >…< branch2 > Show all commits which are present in < branch2 > but not < in branch1 >
git log --not --remotes=< remote > Show commits which are present locally but not in < remote >
git stash save Save the current changes in the next available stash position
git stash list List all available stashes
git stash apply stash@{0} Re-apply the stash at position 0
git stash drop stash@{0} Delete the stash at position 0
git stash branch < branchname > stash@{0} Create a new branch based on the stash at 0
–index Include the indexwhen saving or applying a stash
git pull BRANCHNAME
git push origin HEAD:refs/for/BRANCHNAME
git push origin HEAD:refs/for/master
删掉错误的commit:
根据–soft -mixed –hard,会对working tree和index和HEAD进行重置:
git reset --mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息
git reset --soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可
git reset --hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容
HEAD 最近一个提交
HEAD^ 上一次
<commit_id> 每次commit的SHA1值. 可以用git log 看到,也可以在页面上commit标签页里找到.
gitk 可视化查看commit change
git mergetool gui merge conflict
查看commit文件列表
git log --name-only -1
git log --pretty=format:"" --name-only -1
查看文件更改历史
gitk filename
git log filename
git log -p filename 查看文件历史和diff
Tag operation
git tag -a tagname -m ‘xxx’
git tag -d tagname
git show tagname
#列出打tag的日期和tag
git for-each-ref --sort=taggerdate --format ‘%(refname) %(taggerdate)’ refs/tags
查看改动
git diff filename
git blame filename