git 断点续传
适用于 git clone 时,报错或大项目总是网络中断的情况
- 新建目录,命令行进入目录,执行 git init
- 命令行执行: git fetch 项目地址
- 若步骤 2 失败,重复执行步骤 2, 直到完成下载
- 执行 git checkout FETCH_HEAD
- 执行 git remote add origin 项目地址
- 执行 git pull origin master(根据项目分支实际情况,也可能不是 master)
- 执行 git checkout master(根据项目分支实际情况,也可能不是 master)
github 同步 fork 项目的更新
首先要先确定一下是否建立了主repo的远程源:
git remote -v
如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源:
git remote add upstream URL
git remote -v
然后你就能看到upstream了。 如果想与主repo合并:git fetch upstream
git merge upstream/master
档案暂存
(git add . 之后,git commit 之前) 当修改到一半,需要更新代码时使用
git stash
git stash list
拉取新的代码
git pull
取出修改一半的代码
git stash pop
git stash clear: 清空Git栈
创建并切换到新分支
git checkout -b new_branch
推送新的分支到远程
git push -u origin new_branch
git checkout -b 本地分支名 origin/远程分支名
拉取远程分支
git pull <远程主机名> <远程分支名>:<本地分支名>
git fetch 相当于是从远程获取最新到本地,不会自动merge
git fetch orgin master //将远程仓库的master分支下载到本地当前branch中
git clone -b <指定分支名> <远程仓库地址>
git fetch后,查看其他人员的修改记录 git difftool origin
clone 所有分支
mkdir repo #创建一个空文件夹
cd repo
使用bare方式clone代码。并把下载后的文件夹重命名为 .git
git clone --bare path/to/repo.git .git
使用该命令(不用担心core.bare是否存在) 或 git config --bool core.bare false
git config --unset core.bare
上面的命令执行完,再执行该命令,就可以看到仓库里面的内容了
git reset --hard
git submodule
第一次添加子模块
git submodule add https://github.com/jieiku/abridge.git themes/abridge
pull 时拉取子模块
git pull --recurse-submodules
copy the new URL to your local config
git submodule sync --recursive
update the submodule from the new URL
git submodule update --init --recursive