Git常用命令小记

来源:互联网 发布:杭州金融投资集团 知乎 编辑:程序博客网 时间:2024/06/06 15:39
  • merge时将另一个分支多次提交合并为一次
git merge --squash <branch-name>
  • 在本地仓库与远程仓库之间建立连接
% git remote add origin <url>  #在本地仓库与远程仓库之间建立连接
  • 只克隆最新的提交得版本
% git clone --depth 1  <url>  #只克隆最新的提交得版本
  • 查看当前远程仓库和地址
% git remote -v   # 查看当前远程仓库和地址
  • 本地分支版本强行覆盖远程分支
% git push [-f | --force]
  • git提交时Windows自动修改linux文件权限的解决办法

将linux中的项目直接放到windows下开发,发现用git提交修改时windows默认修改文件权限:
755 => 644 即去除了所有文件的执行权限。

那么如何设置git提交文件时不提交权限法修改呢?

#git中可以加入忽略文件权限的配置,具体如下:% git config core.filemode false#这样就设置了忽略文件权限。查看下配置:% cat .git/config
  • 在windows下git add 时warning: LF will be replaced by CRLF in folder/解决办法

有时,在windows下git add *的时候报错:

warning: LF will be replaced by CRLF in ....

原因:
LF是linux下的换行符,而CRLF是enter + 换行。

解决办法:

git config --global core.autocrlf false
  • Git(github或gitlab)不需重复输入账号和密码的方法

1 创建文件存储GIT用户名和密码

在%HOME%目录中,一般为C:\users\Administrator,创建文件名为.git-credentials的文件,由于在Window中不允许直接创建以”.”开头的文件,所以需要借助git bash进行,打开git bash客户端,进入%HOME%目录,然后用vim创建文件 .git-credentials输入内容格式:

vim .git-credentials#若使用github,输入如下内容https://{username}:{password}@github.com#若使用gitlab,输入如下内容https://{username}:{password}@gitlab.com

2 添加Git Config 内容

进入git bash终端, 输入如下命令:

git config --global credential.helper store

执行完后查看%HOME%目录下的.gitconfig文件,会多了一项:

[credential]    helper = store

重新开启git bash会发现git push时不用再输入用户名和密码

  • 如何解决Git的大小不敏感问题呢?

1.一是设置Git大小写敏感:

$ git config core.ignorecase false

2.二是先删除文件,再添加进去:

$ git rm <filename>; git add <filename> ;  git commit -m "rename file"
0 0