git 使用相关

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

Web:https://git-scm.com/
Doc:https://git-scm.com/doc
中文教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/

使用git必须注意的事情:

1. 跨平台使用git时,文件换行符(Windows下CR LF ,linux和mac下LF)转换问题

因为不同操作系统使用的换行符不一致,Windows下使用CR LF ,linux和mac下使用LF,所以要根据情况进行转换
可以使用notepad++进行查看

notepad++查看换行符

使用AutoCRLF参数设置是否转换

* 提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true

* 提交时转换为LF,检出时不转换
git config --global core.autocrlf input

* 提交检出均不转换
git config --global core.autocrlf false
SafeCRLF
* 拒绝提交包含混合换行符的文件
git config --global core.safecrlf true

* 允许提交包含混合换行符的文件
git config --global core.safecrlf false

* 提交包含混合换行符的文件时给出警告
git config --global core.safecrlf warn

所以根据情况进行设定,比如在linux下编辑,则文件是LF换行,提交到云端时无论设不设置都一样,当需要克隆到Windows时,如果设置了检出自动转换,克隆下来的文件是CRLF结尾的,如果编译器编辑器支持CRLF格式的,则没问题;’如果不支持这时候就会出问题,需要设置不自动转换

二进制文件

在文件.gitattributes中可以指定哪些文件是二进制文件,从而防止二进制文件在提交时被修改,比如.a文件,如果不设置,提交后可能CRLF会被替换成LF,从而导致无法使用,编译提示

error adding symbols: file truncated

.gitattributes中加入

*.a binary

不但如此,还可以单独指定哪些文件使用CRLF结尾,或者是字符文件,比如:

version.h -text
*.vcxproj text eol=crlf
*.props text eol=crlf
*.bat text eol=crlf
* text eol=lf

git lfs

安装:

删除子模块

git不支持命令删除子模块,需要手动删除

  • 删除.gitmodules内的对应子模块的字符,并且git add .gitmodules
  • 删除子模块文件夹
  • 删除.git文件夹下config文件内的对应子模块的内容
  • 删除缓存git rm --cached 子模块路径(相对于仓库根目录)
  • git commit -m "remove submodule..."

从其它的远程仓库合并到本地仓库

# 本地已经有一个远程或者没有,都没关系,假设已经有一个叫 origin
git remote -v
git remote add origin2 git@......git
git remote update
git checkout -b new origin2/master
git checkout master
git merge new
git push origin master

或者参考 github 合并指令:

Merging via command line
If you do not want to use the merge button or an automatic merge cannot be performed, you can perform a manual merge on the command line.

Step 1: From your project repository, check out a new branch and test the changes.

git checkout -b new master
git pull https://github.com/xxx/xxxx.git branch_name

Step 2: Merge the changes and update on GitHub.

git checkout master
git merge --no-ff new
git push origin master

参考:git 换行符LF与CRLF转换问题

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • git 配置多个SSH-Key生成并部署SSH key Git 忽略一些文件不加入版本控制: 在Git中如果想忽略...
    才兄说阅读 355评论 0 1
  • 不同的操作系统有不同的换行符格式,跨平台协作时需要考虑版本工具(git)对换行符的处理 回车和换行 回车(Carr...
    小熊猜猜我有几颗糖阅读 14,318评论 0 7
  • 主题:git add处理不同系统的CRLF问题 将代码从工作区加入暂存区时出现CRLF和LF转换的问题,正好一年前...
    LeeBoot阅读 973评论 0 1
  • 操作系统 window10学习来源: http://www.liaoxuefeng.com/wiki 常用 创建...
    hopevow阅读 792评论 0 17
  • 成都的午后,蝉鸣地响亮,像呼啸而来的飒飒秋风,一阵一阵,人民公园鹤鸣茶社的竹椅上我分不清它们的方向,只觉得它们在...
    自然律阅读 661评论 2 4