git及常用命令

git

Git是一个快速,开源,分布式的版本控制系统,用来保留工程源代码历史状态的命令行工具,类似于SVN,CVS或者Perforce等工具。

通过 git commit告诉 Git 你想保存一份项目快照, Git 就会为你的项目中的各个文件的当前状态存一份记录。之后,绝大部分的 Git 命令都围绕这些记录展开。 比如查看它们的区别(diff),提取它们的内容等.

git仓库,存放你要保存快照数据(本地初始化一个目录)

1 安装git,并初始化

1 配置使用git仓库的用户名
git config –global user.name “Your Name Comes Here”
2 配置使用git仓库的邮箱
git config –global user.email ‘xxx’

2 生成SSH密钥过程:(通过邮箱生成)

$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
设置密码,或默认为空
最后得到了两个文件:id_rsa和id_rsa.pub

3 添加密钥到csdn,ssh公钥管理

4 命令说明列表:

1 将一个目录初始化为Git仓库
git init
生成目录如下:./  ../  .git/


2 第一次拷贝一个Git仓库到本地
git clone git://code.csdn.net/cjqh_hao/thinkphp.git


3 查看文件在工作目录与缓存的状态
git status 

4 将当前工作目录中更改或者新增的文件加入到Git的索引中
git add --all


5 显示已写入缓存与已修改但尚未写入缓存的改动区别
git diff

6 记录缓存内容的快照,-m 选项以在命令行中提供提交注释,-a 想要快照所有所做的改动的时候执行
git commit -a -m '提交信息'

7 取消缓存已缓存内容
git reset HEAD <filename> to unstage

8 将文件从缓冲区删除,删除 Git 追踪的文件。它还会删除你的工作目录中的相应文件。
git rm

9 显示当前分支
git branch

10 显示所有分支(包括远端分支)
git branch -a

11 切换到新的分支
git checkout <branchname>

12 合并分支
git merge
合并冲突

13 删除远端分支
git branch -r -d origin/<branchname>
git push origin :branchname


14 将本地commit的代码更新到远端仓库中,远端有,合并;远端无,创建
git push origin branchanme

15 从服务器的仓库中获取代码,和本地代码合并
git pull (或 git pull origin branchname)

16 从服务器拉取某个分支,并在本地创建同名分支
git fetch origin branchname:banchname

17 查询远端仓库信息
git reomte -v

18 查看历史日志,包含每次的版本变化。每次版本变化对应一个commit id。 
git log 
git log -1 
-1的意思是只显示一个commit,如果想显示5个,就-5。不指定的话,git log会从该commit一直往后显示。 

19 只寻找某个特定作者的提交
git log –author( git log --author='gaoqi')

12 为项目添加一个远端仓库
git remote add

20 删除一个远端仓库
git remote rm

21 使用tig工具
图形化的git工具,命令弱于git

22 合并多个commit
git rebase -i HEAD~X 

23 图形化展示commit
git log --graph --pretty

23 暂存修改操作
git stash save ''
git stash pop
git stash apply stash{x}
git stash list
git stash clear

24 命令列表:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG
   config    更改Git的各种设置
   stash     将当前未提交的工作存入Git工作栈中

25 配置列表
git config -l
-----------------
color.ui=true
color.status=auto
user.email=gaoqi@yunniao.me
user.name=gaoqi
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=ssh://git@dev.xunhuji.me:17999/beeper/beeper_tms_waybill.git
branch.master.remote=origin
branch.master.merge=refs/heads/master

26 git pull报错问题解析
error: some local refs could not be updated; try running
 'git remote prune origin' to remove any old, conflicting branches

在本地master分支上执行git pull 时,提示以上错误信息

git branch –a 用来查看所有的分支,包括本地和远程的
git branch -r 查看远端分支

但是时间久了,有些分支在远程其实早就被删除,但是在你本地依然可以看见这些被删除的分支,那么执行git pull 就会出现这个问题,报错信息里提示执行git remote prune origin来处理。

git remote show origin  来查看有关于origin的一些信息,包括分支是否tracking
通过命令git remote prune 移除无法跟踪的分支。(即刷新本地仓库与远程仓库的保持这些改动的同步)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值