git使用问题与技巧

1.

如果gitolite原来的管理员已经没了,那么需要把当前的公钥放到服务器覆盖,然后替换目录下.ssh/authorized_keys内容

2.

warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 19371 and retry the command.

解决方案:
You need to set and unset that rename limit:

git config merge.renameLimit 999999 //这一条就可以用,下面这条没有用到
git config --unset merge.renameLimit

3.

gitignore
里面的忽略规则是顺序的,比如上面不忽略txt,下面再写入忽略a.txt,那么a.txt就会被忽略

4.

把两个不同的仓库合并到一起

$ git remote -v
origin  git@192.168.1.1:lib.git (fetch)
origin  git@192.168.1.1:lib.git (push)
$ git remote -v
origin  git@192.168.1.1:pro.git (fetch)
origin  git@192.168.1.1:pro.git (push)

把lib合并到pro

$ git remote add slib git@192.168.1.1:lib.git

在pro的分支下运行上面的命令,把lib远程仓库添加到pro下,昵称是slib

$ git fetch slib

把代码拉到本地

$ git checkout -b test slib/master

把本地拉取的lib的仓库,切换到一个test分支,防止合并冲突不好解决

$ git checkout prodev
Checking out files: 100% (14522/14522), done.
Switched to branch 'prodev'

切回到pro的一个分支

$ git merge test
fatal: refusing to merge unrelated histories

把test merge过来,就可以了,可能会有上面错误

$ git merge test --allow-unrelated-histories
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

添加上面命令,强制merge过来
解决冲突提交,就可以了

5.

git commit --amend 重新提交,更改提交日志

6.

gitignore忽略文件夹下的所有文件,但是排除某些目录

先不忽略目录
!application/

再忽略目录下的所有文件
application/*

再屏蔽不忽略的目录
!application/language/

7.

拆分仓库

  1. 修改仓库目录,改成拆分后的结构
  2. 创建一个当前分支的拷贝分支
  3. git filter-branch -f --tag-name-filter cat --prune-empty --subdirectory-filter publish HEAD 运行命令,把publish目录下的内容和历史记录拆分到当前目录,删除所有其他的文件和历史记录,HEAD是当前分支
  4. 创建新的远程仓库
  5. 设置当前的remote为新创建的仓库 git remote set-url origin [email protected]:test.git
  6. 把当前分支推送到远程的master git push -u origin test:master
  7. 切换到原来的分支
  8. 设置回来原来的远程仓库
  9. 删除测试分支

猜你喜欢

转载自www.cnblogs.com/studywithallofyou/p/11356482.html