github 入门教程:
1、https://www.liaoxuefeng.com/wiki/896043488029600
github原理
github 返回历史版本
1 可以使用git log命令获取提交的历史找到需要回滚到的提交点
2 git reset --hard 9f2dc2ab450d922fd9f4faa82af90095de5f5774
3 git push origin master --force
# 撤销前一次 commit
git revert HEAD
# 撤销前前一次 commit
git revert HEAD^
# 撤回指定commit-id
#比如:git revert 0818badf6882ea2664a205bc8ef3a85425bb2537
git revert commit-id
git push original master
github清除untracked 的 文件
# 删除 untracked files
git clean -f
# 连 untracked 的目录也一起删掉
git clean -fd
# 连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)
git clean -xfd
# 在用上述 git clean 前,墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删
git clean -nxfd
git clean -nf
git clean -nfd
git远程分支
https://www.cnblogs.com/sandea/p/9855062.html
使用git checkout -b local_branch_name origin/remote_branch_name创建本地分支关联远程分支
远程生成新分支git push original local_branch_name
删除远程:git push original --delete remote_branch_name
- git 本地分支提交到远程分支:远程先开好分支然后拉到本地
git checkout -b feature-branch origin/feature-branch //检出远程的feature-branch分支到本地
本地先开好分支然后推送到远程
$ git checkout -b feature-branch //创建并切换到分支feature-branch
$ git push origin feature-branch:feature-branch //推送本地的feature-branch(冒号前面的)分支到远程origin的feature-branch(冒号后面的)分支(没有会自动创建)
必须加冒号不然会有新的分支出现
git push origin debug100:xiaogongwei_v1.0 --force
强制推送整个分支被覆盖!!!!!!!
对比本地分支master与远程分支 origin/MG-APPS_Debug 的不同。
git diff master origin/MG-APPS_Debug
git stash
git stash是保存现场调试,然后git stash pop恢复, 然后git stash drop是删除
github 远程分支拉取本地
git fetch origin remote_branch_name
更新本地分支:
git pull origin MG-APPS_Debug:MG-APPS_Debug
github Tag软件版本
https://www.jianshu.com/p/36202c29e6ae
查看git git tag
显示tag信息 git show v1.4
创建git git tag -a v1.0 -m 'first version'
push Git:
git push origin v1.0或者将所有tag 一次全部push到github上 git push origin --tags
//删除github远端的指定tag
git push origin :refs/tags/v1.0.0
Git忽略规则和.gitignore规则不生效的解决办法
https://www.cnblogs.com/zhangxiaoliu/p/6008038.html
在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如果没有这个文件,则需自己手工建立此文件)。这个文件每一行保存了一个匹配的规则例如:
- 此为注释 – 将被 Git 忽略
.sample # 忽略所有 .sample 结尾的文件
!lib.sample # 但 lib.sample 除外
/TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/ # 忽略 build/ 目录下的所有文件
doc/.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
- .gitignore规则不生效的解决办法
把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,原因是.gitignore只能忽略那些原来没有被追踪的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未被追踪状态),然后再提交:
git rm -r --cached .
git add .
git commit -m ‘update .gitignore’
github 永久删除文件和历史记录
参考链接:
https://www.cnblogs.com/shines77/p/3460274.html
步骤1
执行命令git filter-branch --force --index-filter ‘git rm --cached --ignore-unmatch path-to-your-remove-file’ --prune-empty --tag-name-filter cat – --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch projects/Moon.mp3' --prune-empty --tag-name-filter cat -- --all
显示Ref ‘refs/heads/master’ was rewritten说明成功。
步骤2
强制上传:
git push origin master --force
步骤3
清理工作
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
LF will be replaced by CRLF
参考链接:https://www.jianshu.com/p/450cd21b36a4
- 分析
格式化与多余的空白字符,特别是在跨平台情况下,有时候是一个令人发指的问题。由于编辑器的不同或者文件行尾的换行符在 Windows 下被替换了,一些细微的空格变化会不经意地混入提交,造成麻烦。虽然这是小问题,但它会极大地扰乱跨平台协作。
其实,这是因为在文本处理中,CR(CarriageReturn),LF(LineFeed),CR/LF是不同操作系统上使用的换行符,具体如下:
gitignore不起作用
- 解决代码如下:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
- 原因分析:
这个文件里的规则对已经追踪的文件是没有效果的.所以我们需要使用rm命令清除一下相关的缓存内容.这样文件将以未追踪的形式出现.然后再重新添加提交一下,.gitignore文件里的规则就可以起作用了.