【Git】Git问题

MAC在GIT时避免提交.DS_STORE文件

用mac开发项目,每次提交文件时都生成修改文件的 .DS_Store 文件,提交时简直让人抓狂。怎么办呢?我们只需要用 .gitignore 文件去配置Git目录中需要忽略的文件。

.gitignore文件

.gitignore文件里配置用于忽略的文件,格式如下:

  1. #号开头的代表注释符号,会被忽略。
  2. 使用标准的glob模式匹配。
  3. 匹配模式最后的反斜杠(/)代表的是目录。
  4. 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。

操作步骤

  1. 在git目录下新建 .gitignore文件。文件内容加上:
*/.DS_Store
.DS_Store
  1. 保存 .gitignore 文件,表示忽略当前目录的.DS_Store以及其子目录的.DS_Store。
  2. 全局配置要忽略的文件,这个配置文件对所有的Git目录都生效。

创建~/.gitignore_global文件,把需要全局忽略的文件写入该文件,语法和 .gitignore 一样
在~/.gitconfig(git配置文件)中引入.gitignore_global文件

[core] 
excludesfile = /Users/xxx/.gitignore_global 

配置成功

  1. 删除已经提交在git上的.DS_Store文件。使用下面的命令,先将stage中的文件删除,然后提交,再push到远端。
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
git status                  //根据提示删除stage中的文件
git rm --cached filename
git add .gitignore
git commit -m 'delete .DS_Store'
git push origin master

完成,再也没有 .DS_Store 文件的打扰了。

 

 

Q: This is usually caused by another repository pushing:refusing to merge unrelated histories

在已有的仓库中提交一个保存图片的文件夹,git push遇到问题

error: failed to push some refs to '我相关联的git仓库'
hint: Updates were rejected because the remote contains work that you do
!    refs/heads/master:refs/heads/master    [rejected] (fetch first)
Done
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

A: 执行 git pull origin master --allow-unrelated-histories

  • 修改github中的图片大小

1. 不能修改尺寸

![SVM对偶问题](https://github.com/michelleweii/ParallelSMO/blob/master/picture/svm%E5%AF%B9%E5%81%B6%E9%97%AE%E9%A2%98.png)

2. width可以修改尺寸

<img src="https://github.com/michelleweii/ParallelSMO/blob/master/picture/svm%E5%AF%B9%E5%81%B6%E9%97%AE%E9%A2%98.png" width="400" alt="SVM对偶问题">

github删除.DS_Store

关于GitHub上传中忽略.DS_Store的方法说明

git rm --cached .DS_Store

先git clone整个仓库

git clone git@gitlab.xxx.com:xxxxx.git

直接使用命令 git branch -r #查看远程分支

git branch -a #查看所有分支

会显示

origin/HEAD -> origin/master
origin/daily/1.2.2
origin/daily/1.3.0
origin/daily/1.4.1
origin/develop
origin/feature/daily-1.0.0
origin/master

然后直接 git checkout origin/daily/1.4.1

  • 修改git提交的邮箱账号名称

  • Commit提交人信息检查

本机已经有了github的账号,但是要提交代码进公司的git仓库里。

修复方法:

1、更新git全局配置信息,确保user/email信息正确:

命令行直接更新已存在的配置

git config --global --replace-all user.name "<中文名>" 
git config --global --replace-all user.email "<邮箱>"

更新完成后,查看配置信息确保准确无误:

git config --list

2、使用git命令修改“commit message”同时重置当前Commit的user/email:

$ git commit --amend --reset-author

3、使用 git log 确认当前commit的Author信息已经重置。

然后不小心输错了一些信息的话,

使用指度令 git config --global --unset user.name 删除;

或者 git config --global --edit 修改

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值