主要起一个记录的作用,后续有用到会持续更新
0、预备:
1)创建一个本地分支test
git branch test
在默认下,创建一个repo后都会一个master的主分支。我门对分支test的修改不会影响到master。
2)切换分支
git checkout test
切换成test分支后,对test分支进行修改后如果要作用主分支master,可以使用
git checkout master
git merge test
3)删除分支
git branch -d test
1、创建一个repo
2、clone repo
创建好一个repo后,可以把repo先clone下来。这样.git/config配置都是写好的,不容易出错。
然后在clone下来的本地repo右键git bash here。向这个repo添加需要更新的代码等。
3.上传
git add 命令可将该文件添加到暂存区。
git add .#可以添加所有补充的文件
git add filename1[,filename2....]#指定添加
git commit 将暂存区的内容添加到本地repo
git commit -m "string"#string是这次上传文件的简要说明
git pull将远程分支同本地分支合并。
用法:
git pull 远程主机名 远程分支名:本地分支名
倘若使用当前本地分支,那么本地分支名可以省略。
eg.
git pull orign test:master
git push将本地分支更新的代码上传到远程分支。
用法:
eg.
git push orign test:master
将本地的test分支push到远程的master分支上。
不过没人这样用的,一般要保持本地分支名和远程分支名同步。
为了保持同名可以
git push test
会在github上创建一个test分支。
如果push不上去
git push --set-upstream origin test
可能出现的错误
1)git 解决 fatal: ‘origin’ does not appear to be a git repository
远程主机没有和本地关联起来
git remote add origin git@github.com:用户名/repo名
例如上图,用户名/repo名为xxx/gan
2)Git 提示fatal: remote origin already exists
进入到当前本地repo的.git/config删除[remote “orign”]
2、代码合并:
使用如下命令从origin远程仓库获取最新版本的代码
git fetch origin master:test
解释:从远程origin仓库拉取matser分支的版本,并且同时在本地创建一个分支test,拉取到test分支
比较本地的master分支和test分支的差异
git diff test
合并本地master分支和test分支
git merge test
参考:
【1】https://www.runoob.com/w3cnote/git-five-minutes-tutorial.html
【2】https://blog.csdn.net/zeng092210/article/details/95622318