Git换行符

Git会自动处理换行符的问题, 但是这个在实际开发中会出现问题, 所以, 在Windows上使用提交时转换为LF,检出时不转换功能, 统一使用Unix换行符(也可以在类Unix上启用这个功能, 将拉取的没有改变的换行符更换).

Windows打开安装好的Git Bash, 类Unix直接输入:

1
2
git config --global core.autocrlf input
git config --global core.safecrlf warn

含义:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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

Git创建分支、 删除本地和远程分支、 创建tag、 修改tag名称

  • 创建分支: git checkout -b develop

  • 删除本地分支: git branch -d develop

  • 删除远程分支: git push origin :develop

  • 创建tag: git tag -a v1.0.0 -m "message"

  • 推送tag: git push origin --tags

  • 修改tag名称:

    1
    2
    3
    4
    5
    6
    7
    
    git tag new old
    
    git tag -d old
    
    git push origin :refs/tags/old
    
    git push --tags
    
  • 修改commit的信息: 如果这是你最近一次提交并且没有push到远程分支, 可用以下命令直接修改: git commit --amend -m "your new message"