git使用说明

初次使用请参考百度,google,博客园。这里也有一篇入门指南,简练精彩:http://www.kechuandai.net/git%E4%BD%BF%E7%94%A8%E5%B0%8F%E8%AE%B0/

我把自己碰到的问题记录下,备忘。

1 修改文件并提交到github

[luwenwei@dev01v ~/git/helww/labs]$ vim README

[luwenwei@dev01v ~/git/helww/labs]$ git diff 
diff --git a/README b/README
index 39d8172..464c83f 100644
--- a/README
+++ b/README
@@ -3,3 +3,4 @@ This is my github website. Welcome!
 Here is introduction:
 1, labs is my lab, where some joy code is put
 2, this maybe isnot project, but who knows
+3, and some useful testcase

[luwenwei@dev01v ~/git/helww/labs]$ git commit README  -m "small change"
[master b8bc06a] small change
 1 file changed, 1 insertion(+)
[luwenwei@dev01v ~/git/helww/labs]$ git push origin master README
Enter passphrase for key '/home/luwenwei/.ssh/id_rsa': 
error: src refspec README does not match any.
error: 无法推送一些引用到 'git@github.com:helww/labs'

[luwenwei@dev01v ~/git/helww/labs]$ git push origin master 
Enter passphrase for key '/home/luwenwei/.ssh/id_rsa': 
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 695 bytes, done.
Total 6 (delta 1), reused 0 (delta 0)
To git@github.com:helww/labs
   f005d79..b8bc06a  master -> master

解释:

git push origin master README

这句的意思是提交本地的commit到远程仓库,README是要提交的文件,但是此命令执行失败。

正确的命令是:git push origin master(把一次本地commit提交到远程仓库)

2 问题:git push提示origin似乎不是repo

[luwenwei@appdev115 ~/git/helww/labs]$ git pull origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

[luwenwei@appdev115 ~/git/helww/labs]$ git remote add origin git@github.com:helww/labs.git

[luwenwei@appdev115 ~/git/helww/labs]$ git pull origin master                             
The authenticity of host 'github.com (192.30.252.131)' can't be established.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Enter passphrase for key '/home/luwenwei/.ssh/id_rsa': 
来自 github.com:helww/labs
 * branch            master     -> FETCH_HEAD
Already up-to-date.

[luwenwei@appdev115 ~/git/helww/labs]$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Enter passphrase for key '/home/luwenwei/.ssh/id_rsa': 
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 653 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)
To git@github.com:helww/labs.git
   b8bc06a..913fe29  master -> master

解决步骤:1,git remote add origin;2,git pull origin master

1建立本地和远程的映射;2,拉远程代码到本地

3 查看本地修改列表:git diff  --name-status 

[luwenwei@dev01v ~/project/smartcloud/iot_biz]$ git diff  --name-status 
M       deploy/conf.sh
M       deploy/deploy.sh
M       project/autoload_builder.sh
M       project/build_includes.php
M       src/domain/knowledges/constants.php
M       src/proxy/http_proxy.php
D       tags
M       tasks/common_task_header.php
M       test/global.php
M       test/junit.xml

 4 查看本地文件状态:git status(比git diff --name-status好的地方是能把新增的文件也列出来)

[luwenwei@dev01v ~/project/smartcloud/iot_biz]$ git status
# 位于分支 master
# 尚未暂存以备提交的变更:
#   (使用 "git add/rm <file>..." 更新要提交的内容)
#   (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
#    修改:      deploy/conf.sh
#    修改:      deploy/deploy.sh
#    修改:      project/autoload_builder.sh
#    修改:      project/build_includes.php
#    修改:      src/domain/knowledges/constants.php
#    修改:      src/proxy/http_proxy.php
#    删除:      tags
#    修改:      tasks/common_task_header.php
#    修改:      test/global.php
#    修改:      test/junit.xml
#
# 未跟踪的文件:
#   (使用 "git add <file>..." 以包含要提交的内容)
#
#    config/server/server_conf.php.lww
#    deploy/check.sh
#    deploy/deploy-beta.sh
#    src/logic/mnpartner_logic.php
#    src/service/amap_svc.php
#    src/service/position_svc.php
#    tasks/mn_fridge_cosumer.php
#    tasks/mn_fridge_producer.php
#    test/biz-process_log
#    test/env.php
#    test/test_AmapService.php
#    test/test_MnPartnerLogic.php
#    test/test_PostionService.php
#    tools
修改尚未加入提交(使用 "git add" 和/或 "git commit -a"
原文地址:https://www.cnblogs.com/helww/p/4468495.html