常用git命令

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值