tsejx / git-guidebook Goto Github PK
View Code? Open in Web Editor NEW[Archived] Document has been transferred to devops-guidebook.
[Archived] Document has been transferred to devops-guidebook.
在使用 Git 创建项目时候,在两个分支合并的时候会出现以下情况。
有时会在 git pull
或 git push
时候遇到,因为两个分支没有取得关系,也就是原本是独立非关联的。
fatal: refusing to merge unrelated histories
只需要在操作命令后加上 --allow-unrelated-histories
即可解决。
$ git merge master --allow-unrelated-histories
$ git pull origin master --allow-unrelated-histories
解决方式:
# 格式
$ git remote set-url origin git+ssh://[email protected]/<username>/<repository-name>.git
# 例如
$ git remote set-url origin git+ssh://[email protected]/tsejx/git-guidebook.git
用 git rm
来删除文件,同时还会将这个删除的操作记录下来。
用 rm
,仅仅是删除了物理文件,没有将其从 git
的记录中删除。
直观的来讲,git rm
删除过的文件,执行 git commit -m "abc"
提交时,会自动将删除该文件的操作提交上去。
而用 rm
命令直接删除的文件,单纯执行 git commit -m "abc"
提交时,则不会将删除该文件的操作提交上去,需要在执行commit的时候,多加一个-a参数,
即rm删除后,需要使用git commit -am "abc"提交才会将删除文件的操作提交上去。
比如:
# git rm test.file
# git commit -m "delete test.file"
# git push
或者
# rm test.file
# git commit -am "delete test.file"
# git push
# git rm work -r -f
# git commit -m "delete work"
# git push
英文状态下按 Q
1.Checkout
git checkout --orphan latest_branch
git add -A
git commit -am "commit message"
git branch -D master
5.Rename the current branch to master
git branch -m master
6.Finally, force update your repository
git push -f origin master
# old
https://github.com/tsejx/git-guidebook.git
# new
https://github.com/tsejx/Git-Guidebook.git
$ git remote -v
cd
本地仓库目录git remote
查看所有远程仓库,git remote xx
查看远程仓库地址(如 xxx 为 origin)git remote set-url origin https://github.com/tsejx/Git-Guide.git
cd
本地仓库目录git remote
查看所有远程仓库,git remote xx
查看远程仓库地址(如 xxx 为 origin)git remote rm origin
git remote add origin https://github.com/tsejx/Git-Guide.git
cd
本地仓库目录vim config
[remote "origin"]
下的 url 即可参考:Git的错误error: Failed to connect to github.com:443;解决办法
解决方法:
编辑文件 vim /etc/hosts
将 github.com
相关的 dns ip 注释
# 192.30.252.129 github.com
# 192.30.252.131 github.com
# 204.13.251.16 github.com
估计是 github.com 的动态 IP 导致相关问题
假设我把 vuejs fork 到了我的账户下,但是原项目会一直保持更新,我的账户下的 vuejs 并不是最新的代码,因此需要保持与原项目代码保持一致。
https://github.com/tsejx/vue.git
https://github.com/vuejs/vue.git
1. 把 fork 后的仓库克隆到本地
$ git clone https://github.com/tsejx/vue.git
2. 进入根目录,增加远程分支(fork 的分支),名为 update_stream(自定义)到本地
$ git remote add update_stream https://github.com/vue/vue.git
3. 检查状态
通过以下命令会发现多出 update_stream 的远程分支
$ git remote -v
4. 把远程分支 update_stream 的代码拉取到本地
$ git fetch update_stream
5. 合并对方远程原始分支 update_stream 的代码
$ git merge update_stream/master
6. 把最新的代码推送到你的 Github 上
$ git push origin master
7. 如果需要给 update_stream 发送 Pull Request
打开 Github 上你的仓库
点击 Pull Request => 点击 New Pull Request => 输入Title和功能说明 => 点击 Send pull request
git push
同步到远程仓库git fetch
同步远端信息,git tag
后发现本地记录仍有 tagA对于远程仓库中已经删除了的 tag,即使使用 git fetch --prune
,甚至 git fetch --tags
确保下载所有 tags,也不会让其在本地也将其删除的。而且,似乎 git 目前也没有提供一个直接的命令和参数选项可以删除本地的在远程已经不存在的 tag
# 删除所有本地分支
git tag -l | xargs git tag -d
# 从远程拉去所有信息
git fetch origin --prune
由于拼写错误导致需要修改文件名大小写后重新提交代码,结果发现 git status
中并未找到该变化,究其原因是 Git 默认配置了忽略大小写敏感。
解决方法:
# 查看忽略大小写配置项
$ git config core.ignorecase
# 设置大小写敏感为敏感
$ git config core.ignorecase false
git mv -f oldfolder newfolder
git add -u newfolder
-u
选项会更新已经追踪的文件和文件夹。
git commit -m "changed the foldername whaddup"
git mv foldername tempname && git mv tempname folderName
在大小写不敏感的系统中,如windows,重命名文件的大小写,使用临时文件名
git mv -n foldername folderName
(显示重命名会发生的改变,不进行重命名操作)
撤销最近一次 git merge
git reset --merge HEAD^
给 fork 配置远程库
git remote -v
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
再次查看状态确认是否配置成功
同步 fork
git fetch upstream
git fetch upstream
git merge upstream/master
git push origin master
ls -al ~/.ssh
ssh-keygen -t rsa -C "Github UserName"
(双引号内为 Github 用户名),按三次回车cat ~/.ssh/id_rsa.pub
生成新的 SSHA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.