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

如果对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分布式版本控制系统最佳实践 这篇文章来自于老男孩教育高级架构师班12期的徐亮偉同学。 首先感谢老男孩架构师班...
    meng_philip123阅读 3,529评论 4 36
  • git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章阅读 8,668评论 1 26
  • linux基础命令findfind / -name targetfilename 查找文件按时间查找也有参数 -a...
    AQ王浩阅读 1,512评论 0 5
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆阅读 527评论 0 0
  • 窗外有着熙熙攘攘的群人 我有着一颗避世的心 热闹与烦嚣 请为我留下静静的一隅 当我在清冷的世界里享受孤独 诗人的情...
    纤人泪阅读 307评论 10 4