git常用
1.初始化本地仓库 git init
2.将本地仓库内容提交到本地服务器 git commit -m “注释内容” ,此次本地仓库会自动创建master分支
git commit -a -m 相当于 git add 和git commit合并
3.将远程仓库添加到本地 git remote add origin https://github.com/CaribbeanKelp0607/maventest.git
4.查看远程仓库 git remote -v
5.推送数据到远程仓库 git push [remote-name] [branch-name] git push origin master
6.从远程仓库抓取数据 git fetch [remote-name] git fetch origin
7.远程仓库删除和重命名 git remote rename origin newname git remote rm origin
8.创建一个新的分支 git branch testing
9.切换到其他分支 git checkout testing
10.git checkout -b testing 相当于 git branch 和git check 一起执行
11.git checkout时如果有修改但未提交的文件,将不容许切换
12.git merge develop 将develop分支 merge到当前分支上
13.git commit -a 提交全部
14.合并出现冲突
冲突时,首先 git status查看冲突文件,然后手动处理冲突的地方。
可以看到 ======= 隔开的上半部分,是 HEAD(即 master 分支,在运行 merge 命令时所切换到的分支)中的内容,
下半部分是在 iss53 分支中的内容。解决冲突的办法无非是二者选其一或者由你亲自整合到一起。
冲突处理好之后,使用 git add
git add 将把它们标记为已解决状态(译注:实际上就是来一次快照保存到暂存区域。)。因为一旦暂存,就表示冲突已经解决
如果觉得满意了,并且确认所有冲突都已解决,也就是进入了暂存区,就可以用 git commit 来完成这次合并提交。提交的记录差不多是这样:
15.git push (远程仓库名) (分支名)
取出我在本地的 serverfix 分支,推送到远程仓库的 serverfix 分支中去
git push 你可以把本地分支推送到某个命名不同的远程分支:若想把远程分支叫作 awesomebranch,可以用 git push origin serverfix:awesomebranch 来推送数据
16.git fetch origin
在 fetch 操作下载好新的远程分支之后,你仍然无法在本地编辑该远程仓库中的分支。换句话说,在本例中,你不会有一个新的 serverfix 分支,有的只是一个你无法移动的 origin/serverfix 指针
17.git merge
如果要把该远程分支的内容合并到当前分支,可以运行 git merge origin/serverfix。如果想要一份自己的 serverfix 来开发,可以在远程分支的基础上分化出一个新的分支来:
git checkout -b serverfix origin/serverfix
18.git 查看远程分支 git branch -a 或 git branch –all
19.git pull <远程主机名> <远程分支名>:<本地分支名>
比如,要取回origin主机的next分支,与本地的master分支合并,需要写成下面这样 -
gitpulloriginnext:master如果远程分支(next)要与当前分支合并,则冒号后面的部分可以省略。上面命令可以简写为:
g
i
t
p
u
l
l
o
r
i
g
i
n
n
e
x
t
:
m
a
s
t
e
r
如
果
远
程
分
支
(
n
e
x
t
)
要
与
当
前
分
支
合
并
,
则
冒
号
后
面
的
部
分
可
以
省
略
。
上
面
命
令
可
以
简
写
为
:
git pull origin next
20.git clone -b develop https://github.com/uacaps/PageMenu
21.git clone 默认会把远程仓库整个给clone下来;
但只会在本地默认创建一个master分支
22.git fetch <远程主机名> <远程分支名>
可以使用checkout命令来把远程分支取到本地
或者使用-t参数,它默认会在本地建立一个和远程分支名字一样的分支
折叠展开复制代码
$ git checkout -t origin/daily/1.4.1
也可以使用fetch来做:
$ git fetch origin python_mail.skin:python_mail.skin
23.git如何移除某文件夹的版本控制
git rm参数
-n --dry-run
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
-r
Allow recursive removal when a leading directory name is given.
--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
git rm -r -n –cached “bin/” //-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
git rm -r –cached “bin/” //最终执行命令.
git commit -m” remove bin folder all file out of control” //提交
git push origin master //提交到远程服务器
此时 git status 看到 bin/目录状态变为 untracked
可以修改 .gitignore 文件 添加 bin/ 并提交 .gitignore 文件到远程服务器,这样就可以不对bin目录进行版本管理了。
以后需要的时候,只需要注释 .gitignore 里 #bin/ 内容,重新执行 git bin/ ,即可重新纳入版本管理。