git 需要进行远程仓库相关的操作。
1、查看远程仓库操作帮助
$ git remote --help
SYNOPSIS
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>...
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>...
git remote prune [-n | --dry-run] <name>...
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
DESCRIPTION
Manage the set of repositories ("remotes") whose branches you track.
OPTIONS
-v, --verbose
Be a little more verbose and show remote url after name. NOTE: This must be placed between remote and subcommand.
COMMANDS
2. 要将当前仓库迁移到另外一个代码仓库,怎么处理呢?
切换仓库的地址即可。
$ git remote set-url [新的远程仓库地址]
然后将代码推送过去即可。这个切换的就是origin的仓库地址。
这样push 和pull的地址都切换到了新的仓库地址。
$ git push origin [分支]
3. Git恢复已经删除的分支
项目中删除了不小心本地分支,后来发现有很多的代码修改没有保存,
需要进行恢复。这就需要恢复Git的分支。怎么办呢?
1)查看Git修改引用日志,
$ git reflog
df674610e HEAD@{16}: checkout: moving from qtk_zhouronghua to master
874d37c65 HEAD@{17}: reset: moving to HEAD
874d37c65 HEAD@{18}: checkout: moving from qtk_master to qtk_zhouronghua
8b9895078 (origin/master, origin/HEAD, master) HEAD@{19}: pull origin master: Fast-forward
652e3b68d HEAD@{20}: checkout: moving from qtk_zhouronghua to qtk_master
874d37c65 HEAD@{21}: commit: 1.修正乾题库注会首页科目显示问题 2.修正首页TAB刷新问题
:...skipping...
ff056f46a (HEAD -> qtk_zhouronghua_new, origin/qtk_zhouronghua, help) HEAD@{0}: Branch: renamed refs/heads/qtk_zhouronghua to refs/heads/qtk_zhouronghua_new
ff056f46a (HEAD -> qtk_zhouronghua_new, origin/qtk_zhouronghua, help) HEAD@{2}: commit: 购课页面标题栏适配
fc75ddf31 (origin/qtk_zhouronghua_fix, qtk_zhouronghua_fix) HEAD@{3}: checkout: moving from qtk_zhouronghua_fix to qtk_zhouronghua
fc75ddf31 (origin/qtk_zhouronghua_fix, qtk_zhouronghua_fix) HEAD@{4}: commit: 1.修正乾题库注会首页科目显示问题 2.修正首页TAB刷新问题
散列值 874d3c65 HEAD@{21} 是我们需要的分支修改。
2)恢复分支。
为了防止出现冲突。如果有本地已同名的分支,重命名一下
$ git branch -m [原名字] [新名字]
恢复到对应散列值的历史分支。
git branch <branch_name> <hash_val>
$ git branch [分支名] HEAD@{21}
这样就恢复了分支。
3.SVN项目迁移Git
3.1 SVN项目的地址,账号:test/test@123
3.2Git上创建对应的项目
远程仓库地址:https://192.165.22.33/migrate/GitProject
账号/密码: my_test/mytest@123
3.3 创建目标项目
#git svn clone [SVN项目地址] --no-metadata --authors-file=users.txt [迁移到项目下GitProject]
3.3 将克隆的项目关联远程项目
#git remote add origin 【Git项目地址】
可以查看fetch和push的远程地址:
#git remote –v
3.4 创建成功以后进行推送
# git push origin master
4.Git文件大小写冲突
Git默认不区分文件名的大小写,得到两个文件,当用户复制一个文件且修改一个文件名大小写,推送到仓库以后。在其他用户拉取以后,此文件会一直冲突。
这是因为Git默认不区分文件名大小写。拉取的时候,两个大小写不同的同名文件被当做同一个文件,因此会出现冲突。
解决方法:方式一:想要修改文件名,可以删除源文件,然后修改文件名大小写,然后推送到仓库;
方式二:Git支持文件名大小写
$ git config --get core.ignorecase
true
为true表示文件名忽略大小写,文件名大小写不敏感。
$ git config core.ignorecase false