关于git 的使用

git 常用操作:

1:首先创建本地版本库:git init

2:从远程库clone 文件:git clone “这是地址”

注意: 在创建完远程的版本库的时候,会提示我们使用( git remote add origin ”我是萌萌哒的地址“)这个方法来关联远程库,这一步应该是放在第一次提交之前完成。

3:然后可以创建文件、修改文件、删除文件
如果是创建、修改文件的话,使用:git add “文件名”
如果是删除文件的话,使用:git rm “文件名”
现在就可以使用 git status 来查看 git 的状态;
最后使用:git commit -m “本次提交的信息”

4:在第一次做提交的时候,需要和远程仓库的地址做一次绑定git remote add origin “地址”
然后使用:git push-u origin master来提交到master 分支。
以后就直接可以用 git push 来进行提交,默认是提交到当前分支的远程仓库。

5:接下来就是对于 git 的真正使用

如果我们要修改内容,一般都会重新建一个分支,然后在分支上做修改,当我们修改完东西之后,把分支上的东西 进行  add 和 commit 操作,然后合并到 master 分支,最后将这个分支删除。

(1)查看分支 :`git branch`
(2)创建一个分支:`git branch “我是分支的名字”`
(3)切换分支:`git checkout “我是分支的名字”`
(4)创建并切换一个分支:`git checkout -b “我是分支的名字”`
(5)合并某一个分支到当前分支:`git merge “我是分支”`
(6)删除分支:`git branch -d “我是分支”`
(7)强行删除分支:`git branch -D “我是分支”`
(7)可以查看分支的合并图:`git log -- graph`

6:有多个分支的时候

当我们从远程仓库克隆时,实际上 Git 自动把本地的 master 分支和远程的 master 分支对应起来了,并且,远程仓库的默认名称是 origin。

(1)推送自己的分支:`git push origin master` 
(2)推送到其他的分支:`git push origin “分支名”`
(3)创建一个远程的分支到本地 :`git checkout -b develop origin/develop

`(假设远程的分支名脚develop)

(4)删除远程仓库上的某个分支时:`git push origin :“分支名”`

error: you need to resolve your current index first 错误提示:
这是连接:http://stackoverflow.com/questions/6006737/git-merge-errors
解决思路:
1、解决conflicts后再次执行merge;
2、回退到merge前

git reset --merge  

7:这是 git help 下的描述:

The most commonly used git commands are:

   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 integrate 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值