Git 作为个人和公司代码管理的最佳选择方案,熟悉各种常用的 git 命令操作显得尤为重要,这篇博文就作为自己的一个关于 git 常用和不常用命令的笔记,整理走一波!
# git clone <repo> [dirname=repo_name]
git clone https://github.com/Hopetree/izone.git
# git clone -b <branch> <repo> [dirname=repo_name]
git clone -b dev https://github.com/Hopetree/izone.git
指定深度可以减少克隆的时候下载文件的大小,如果只需要克隆最后一次提交,可以设置 --depth=1
这样可以有效减少历史提交的二进制文件的大小,使得克隆代码更小,花费的时间也会更短
git clone --depth=1 https://github.com/Hopetree/izone.git
git push origin --tags
git add *
添加 .gitignore 中忽略的文件:
git add -f .env
git checkout .
# git checkout -- <filename>
git checkout -- readme.md
# 首先要取消文件的暂存状态,执行取消暂存命令,然后执行删除修改的命令
# git reset HEAD -- <filename>
git reset HEAD -- readme.md
git checkout -- readme.md
# git checkout <branch>
git checkout dev
git checkout -b dev origin/dev
# git branch -d <branch>
git branch -d dev
# 当分支上面还有未完成的提交时,需要强制删除
git branch -D dev
git branch -r
git remote update origin -p
git branch -r
# git push origin --delete <branch>
git push origin --delete dev
要将A分支的一个commit合并到B分支,可以进行如下操作
# git tag -a <tag_name> -m 'tag 注释'
git tag -a v1-1.0 -m 'tag 注释'
# 推送本地所有tag
git push origin --tags
# 推送单个tag
git push origin <tagname>
# git tag -d <tag_name>
git tag -d v1-1.0
# git push origin --delete tag <tag_name>
git push origin --delete tag v1.0
# git reset --hard <commit SHA>
git reset --hard 7ad2e20d94ebfae5391bee38628ecfccf15982ac
# git push -f origin <branch>
git push -f origin dev
报错内容包含如下信息
fatal: Authentication failed for 'http://xxx'
这种错误一般都是跟用户账号有关,如果是clone的话,可以在clone命令中显式添加账号信息然后clone,命令如下:
git clone http://username:password@github.xxx.git
在github上,如果未指定语言,Linguist来自动识别你的代码应该归为哪一类,它是根据某种语言的代码量来决定是哪种语言的项目。如果识别有误,可以新建.gitattributes文件来进行设置。格式如下:
*.js linguist-language=python
*.css linguist-language=python
*.html linguist-language=python
统计某段时间内某个人代码提交量
git log --author="$(git config --get user.name)" --pretty=tformat: --numstat --since ==2019-8-1 --until=2019-9-1| gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
参考:https://blog.csdn.net/yjaspire/article/details/80921000
阮一峰博客:http://www.ruanyifeng.com/blog/2019/12/git-undo.html
版权声明:如无特殊说明,文章均为本站原创,转载请注明出处 本文链接:https://cloud.tencent.com/developer/article/2123502 许可协议:署名-非商业性使用 4.0 国际许可协议