美文网首页
git命令基本用,应对日常操作

git命令基本用,应对日常操作

作者: 吊炸 | 来源:发表于2016-11-30 23:34 被阅读128次

如果对git命令行不熟悉的话,用git图形界面工具,就比较合适了。建议使用tortoisegit 或sourectree这样的工具,命令行从学习到灵活掌握的时间成本比较高的。

1,添加

# git clone git@192.168.10.202:develop/test.git

# cd test

# touch test.txt //测试文件

# git add test.txt //git添加文件到缓存区

# git commit -m 'test' //添加到本地版本库

# git push //push到远程服务器

如果push报错,Perhaps you should specify a branch such as 'master'

解决办法:

# git push origin master //只要这样操作一次,以后就可以用git push

添加文件和添加目录,操作是一样的。

2,修改文件

方法一

# echo "11111111111" > test.txt

# git add test.txt && git commit -m 'test2'

# git push

方法二

# echo "abc" > test.txt

# git commit -am "test3" //所有修改都会提交

# git push

如果有多个文件,只想提交其中的一个或者多个,怎么办呢

# git commit -a //该命令出现以下内容

# Please enter the commit message for your changes. Lines starting

# with '#' will be ignored, and an emptyempty message aborts the commit.

# On branch master

# Changes to be committed:

# (use "git reset HEAD ..." to unstage)

#

# modified: ab

# modified: test.txt //如果只想提交test.txt,只要把该行前的#去掉,保存退出就行了

# git push //退出后,在执行push

3,删除

# git rm ab //如果删除目录的话,加上-r

# git commit -am "del"

# git push

4,解决冲突

# git push //push不上去

Address 192.168.10.202 maps to unassigned.psychz.net, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

To git@192.168.10.202:develop/test.git

! [rejected] master -> master (non-fast-forward)

error: failed to push some refs to '192.168.10.202:develop/test.git'

To prevent you from losing history, non-fast-forward updates were rejected

Merge the remote changes before pushing again. See the 'Note about

fast-forwards' section of 'git push --help' for details.

# git pull //更新代码,提示冲突

Address 192.168.10.202 maps to unassigned.psychz.net, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From 192.168.10.202:develop/test

367dad3..5e5640b master -> origin/master

Auto-merging test.txt

CONFLICT (content): Merge conflict in test.txt

Automatic merge failed; fix conflicts and then commit the result.

# vim test.txt //修改冲突文件,并保存

# git commit -am "remove conflict" //重新提交到本地版本库

# git push //同步到远程

相关文章

  • git命令基本用,应对日常操作

    如果对git命令行不熟悉的话,用git图形界面工具,就比较合适了。建议使用tortoisegit 或sourect...

  • GIt 操作补充

    常用的git操作命令 常用的git操作命令已经能够满足日常的工作需求 现补充一些高级命令 git branch -...

  • 任务4(2)

    一、Git基本操作 1.git init命令 用 git init 在目录中创建新的 Git 仓库。 你可以在任何...

  • git 命令

    一、git 操作命令 1. 基本命令 (顺序操作) git init 初始化一个git仓库 git stat...

  • Android Studio + Git(JetBrain全家桶

    观察了下身边同事操作git基本上都是用git命令行或者tortoise git。但是在windows下使用命令行得...

  • git基本操作整理

    git基本操作整理 之前用的svn,很少使用命令,如今要使用gitlab,所以整理一下 git 的简单用法。 基本...

  • Git第一步之Git提交

    基本操作 下文主要是写了日常Git提交和同步线上的一些日常操作 克隆 git clone <项目目...

  • git常用命令

    初始配置 常用命令 git操作原则 vim基本操作

  • 浅谈gitflow

    之前文章对git的日常操作做了简单的总结,本篇主要对gitflow进行说明和总结。 git日常的基本操作 Git ...

  • git 基本操作

    git基本操作命令 1、克隆代码 git clone git@xxxxxx:xxxxxx/xxx.git2、查看...

网友评论

      本文标题:git命令基本用,应对日常操作

      本文链接:https://www.haomeiwen.com/subject/uexxmttx.html