赞
踩
1.远程拉取gitlab 工程分支,并在本地建立分支
具体过程
- 新建一个空文件
- 初始化 git init
- 自己要与origin master建立连接(下划线远程仓库链接)
git remote add origin http://192.168.9.10:8888/root/game-of-life.git- 把远程分支拉到本地(game-of-live-first_branch为远程仓库的分支名)
git fetch origin game-of-live-first_branch- 在本地创建分支game-of-live-first_branch并切换到该分支
git checkout -b game-of-live-first_branch origin/game-of-live-first_branch- 把game-of-live-first_branch远程分支上的内容都拉取到本地
git pull origin game-of-live-first_branch
2.修改分支的内容并上传给远程分支
3.如果想在linux中拉取远程分支代码
[root@localhost rollBack]# git init
Initialized empty Git repository in /test/rollBack/.git/
[root@localhost rollBack]# git remote add origin git@192.168.9.10:root/game-of-life.git
[root@localhost rollBack]# git fetch origin game-of-live-first_branch
remote: Enumerating objects: 1770, done.
remote: Counting objects: 100% (1770/1770), done.
remote: Compressing objects: 100% (582/582), done.
remote: Total 1770 (delta 1112), reused 1770 (delta 1112)
Receiving objects: 100% (1770/1770), 15.00 MiB | 28.20 MiB/s, done.
Resolving deltas: 100% (1112/1112), done.
From 192.168.9.10:root/game-of-life
- branch game-of-live-first_branch -> FETCH_HEAD
[root@localhost rollBack]# git pull origin game-of-live-first_branch
From 192.168.9.10:root/game-of-life- branch game-of-live-first_branch -> FETCH_HEAD
4.git使用
4.1.源码安装git
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum -y install perl-ExtUtils-MakeMaker package
[root@localhost ~]# tar xvf git-2.9.5 -C /usr/src/
[root@localhost ~]# cd /usr/src/git-2.9.5
[root@localhost git-2.9.5]# make configure
GIT_VERSION = 2.9.5
GEN configure
[root@localhost git-2.9.5]# ./configure --prefix=/usr/local/
[root@localhost git-2.9.5]# make && make install
4.2.配置git
[root@localhost git-2.9.5]# git config --global user.name "yunjisuan" #配置git使用用户
[root@localhost git-2.9.5]# git config --global user.email "102110504@qq.com" #配置git使用邮箱
[root@localhost git-2.9.5]# git config --global color.ui true #语法高亮
[root@localhost git-2.9.5]# git config --list 查看全局配置br/>user.name=yunjisuan
user.email=102110504@qq.com
color.ui=true[root@localhost ~] # cat .gitconfig
[user]
name = clsn
email = admin@znix.top
[color]
ui = true
1)没有添加到暂存区的数据直接mv/rename改名即可。
2)已经添加到暂存区数据:
git mv README NOTICE #这个改的时候工作目录里的文件名字也改了
mkdir: //XX (创建一个空目录 XX指目录名)
pwd: // 显示当前目录的路径。
git init //把当前的目录变成可以管理的git仓库,生成隐藏.git文件。
git add XX //把xx文件添加到暂存区去。
git commit –m “XX” //提交文件 –m 后面的是注释。
git status //查看仓库状态
git diff XX // 查看XX文件修改了那些内容
git log //查看历史记录
git reset --hard HEAD^ //或者 git reset --hard HEAD~ 回退到上一个版本(如果想回退到100个版本,使用git reset –hard HEAD~100 )
cat XX //查看XX文件内容
git reflog //查看历史记录的版本号id
git checkout -- XX //把XX文件在工作区的修改全部撤销。
git rm XX //删除XX文件
git checkout –b dev //创建dev分支 并切换到dev分支上
git branch //查看当前所有的分支
git checkout master // 切换回master分支
git merge dev //在当前的分支上合并dev分支
git branch –d dev //删除dev分支
git branch name //创建分支
git stash //把当前的工作隐藏起来 等以后恢复现场后继续工作
git stash list //查看所有被隐藏的文件列表
git stash apply //恢复被隐藏的文件,但是内容不删除
git stash drop //删除文件
git stash pop //恢复文件的同时 也删除文件
git remote //查看远程库的信息
git remote –v //查看远程库的详细信息
git remote add origin GitHub: Where the world builds software · GitHub-- //关联一个远程库 --为路径
git push –u origin master //(第一次要用-u 以后不需要)把当前master分支推送到远程库
git push origin master //Git会把master分支推送到远程库对应的远程分支上
git clone https://github.com/--- // 从远程库中克隆 --为路径
远程仓库相关命令 检出仓库: $ git clone 查看远程仓库:$ git remote -v 添加远程仓库:$ git remote add 删除远程仓库:$ git remote rm 修改远程仓库:$ git remote set-url --push 拉取远程仓库:$ git pull 推送远程仓库:$ git push *如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下: $git push origin test:master // 提交本地test分支作为远程的master分支 $git push origin test:test // 提交本地test分支作为远程的test分支
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。