git学习心得

   git是一款十分有用的版本控制软件,程序员必备。

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743256916071d599b3aed534aaab22a0db6c4e07fd0000


1.生成key 

 ssh-keygen -t rsa 
将生成的位于.ssh下的pub文件cat后,复制到git的ssh key当中。


2.在.ssh目录下2新建config,加入port XXXX (端口)


3.修改config权限 chmod 600


4.git pull origin master 该步骤要位于当前工作空间之下

当前工作空间:

F:\Program Files\Git\guoxungit\hearthdap-front



//取消更改 回滚到上次状态

1.git reset --hard

2.git reset --hard head^^ //回滚到上上次 ……head~1//回滚到上一次版本


一.提交代码操作流程:

1.查看当前本地分支 git branch


2.查看网络分支 git branch -a


3.添加本地分支 git branch guoxun


4.切换到本地分支 git checkout guoxun


5.git status 查看当前文件状态


6.文件的三种状态 只有暂存区域的文件(即:文件状态为“Changes to be committed”)才会被提交
http://phplaber.iteye.com/blog/1699926
除了之前的“Changes to be committed”状态,现在又多了一条“Changes not staged for commit”状态,表明文件已经修改,但是还没有放入暂存区域,也就是没生成快照。如果现在进行commit操作,只是将修改之前的文件快照提交到了git目录,一定记住:只有暂存区域的文件(即:文件状态为“Changes to be committed”)才会被提交。正如提示,通过“git add README.txt”命令将已修改文件更新到暂存区域中,如果想撤销修改,可以使用“git checkout -- README.txt”命令


7.git add application/ 将以application开头的文件设为Changes to be committed状态


8.git reset HEAD .idea 将以.idea开头的文件从change to be committed状态回退到前一个状态


9.git log 查看近期修改日志


10.git commit -m "add index of help" 提交


11.git push origin guoxun 把修改提交到分支上


操作记录:



admin@guoxun MINGW64 /guoxungit (master)
$ git branch
* master


admin@guoxun MINGW64 /guoxungit (master)
$ git checkout


admin@guoxun MINGW64 /guoxungit (master)
$ git branch -a
* master
  remotes/origin/master


admin@guoxun MINGW64 /guoxungit (master)
$ git branch guoxun


admin@guoxun MINGW64 /guoxungit (master)
$ git branch
  guoxun
* master


admin@guoxun MINGW64 /guoxungit (master)
$ git checkout test
error: pathspec 'test' did not match any file(s) known to git.


admin@guoxun MINGW64 /guoxungit (master)
$ git checkout guoxun
Switched to branch 'guoxun'


admin@guoxun MINGW64 /guoxungit (guoxun)
$ git push origin guoxun
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:hui.chen/hearthdap-front.git
 * [new branch]      guoxun -> guoxun


admin@guoxun MINGW64 /guoxungit (guoxun)
$ ls
application/  hearthdap-front/  spacerscoringcrispr-code/
assets/       index.php         system/
download/     license.txt       user_guide/


admin@guoxun MINGW64 /guoxungit (guoxun)
$ cd hearth-front
bash: cd: hearth-front: No such file or directory


admin@guoxun MINGW64 /guoxungit (guoxun)
$ cd hearthdap-front/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (master)
$ ls
application/  CodeIgniter-3.0.2.zip  index.html  license.txt  user_guide/
assets/       download/              index.php   system/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (master)
$ git branch guoxun


admin@guoxun MINGW64 /guoxungit/hearthdap-front (master)
$ git checkout guoxun
A       .idea/vcs.xml
M       application/libraries/Cipredis.php
Switched to branch 'guoxun'


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git push origin guoxun
Everything up-to-date


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git commit
Aborting commit due to empty commit message.


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git commit -m "helpindex"
error: pathspec 'helpindex' did not match any file(s) known to git.


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   .idea/vcs.xml


Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


        modified:   application/libraries/Cipredis.php


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/.name
        .idea/copyright/
        .idea/deployment.xml
        .idea/encodings.xml
        .idea/hearthdap-front.iml
        .idea/misc.xml
        .idea/modules.xml
        .idea/workspace.xml
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        application/controllers/helpIndex.php
        application/views/helpIndex.tpl
        assets/images/helpView.jpg
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/
controllers/ libraries/   views/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add assets/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git satus
git: 'satus' is not a git command. See 'git --help'.


Did you mean this?
        status


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   .idea/vcs.xml
        new file:   assets/images/helpView.jpg


Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


        modified:   application/libraries/Cipredis.php


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/.name
        .idea/copyright/
        .idea/deployment.xml
        .idea/encodings.xml
        .idea/hearthdap-front.iml
        .idea/misc.xml
        .idea/modules.xml
        .idea/workspace.xml
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        application/controllers/helpIndex.php
        application/views/helpIndex.tpl
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git add application/


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   .idea/vcs.xml
        new file:   application/controllers/helpIndex.php
        modified:   application/libraries/Cipredis.php
        new file:   application/views/helpIndex.tpl
        new file:   assets/images/helpView.jpg


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/.name
        .idea/copyright/
        .idea/deployment.xml
        .idea/encodings.xml
        .idea/hearthdap-front.iml
        .idea/misc.xml
        .idea/modules.xml
        .idea/workspace.xml
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git rm .idea
fatal: not removing '.idea' recursively without -r


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git rm .idea/
fatal: not removing '.idea/' recursively without -r


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git rm .idea/vcs.xml
error: the following file has changes staged in the index:
    .idea/vcs.xml
(use --cached to keep the file, or -f to force removal)


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git checkout
A       .idea/vcs.xml
A       application/controllers/helpIndex.php
M       application/libraries/Cipredis.php
A       application/views/helpIndex.tpl
A       assets/images/helpView.jpg


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   .idea/vcs.xml
        new file:   application/controllers/helpIndex.php
        modified:   application/libraries/Cipredis.php
        new file:   application/views/helpIndex.tpl
        new file:   assets/images/helpView.jpg


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/.name
        .idea/copyright/
        .idea/deployment.xml
        .idea/encodings.xml
        .idea/hearthdap-front.iml
        .idea/misc.xml
        .idea/modules.xml
        .idea/workspace.xml
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git reset head .idea/vcs.xml


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   application/controllers/helpIndex.php
        modified:   application/libraries/Cipredis.php
        new file:   application/views/helpIndex.tpl
        new file:   assets/images/helpView.jpg


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git reset head application/libraries/Cipredis.php
Unstaged changes after reset:
M       application/libraries/Cipredis.php


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   application/controllers/helpIndex.php
        new file:   application/views/helpIndex.tpl
        new file:   assets/images/helpView.jpg


Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


        modified:   application/libraries/Cipredis.php


Untracked files:
  (use "git add <file>..." to include in what will be committed)


        .idea/
        .project
        .settings/
        CodeIgniter-3.0.2.zip
        index.html




admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git checkout application/libraries/Cipredis.php


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git log
commit f258c36490d35ff956d47956bfb67bfc45eaf940
Merge: d1a272e 30ae67c
Author: Hui.Chen <[email protected]>
Date:   Thu Jan 14 16:32:26 2016 +0800


    Merge branch 'dev' of git.qyidea.com:hui.chen/hearthdap-front


commit d1a272e9d568c5f60c0e1f5eda76765d5d67c090
Author: Hui.Chen <[email protected]>
Date:   Thu Jan 14 16:31:22 2016 +0800


    remove authorized_keys


commit 30ae67c27ccb6e72552e8f08f51e69de0125bef0
Author: sjh <[email protected]>
Date:   Tue Jan 12 16:21:11 2016 +0800


    Get match datas from db and fill in the table


commit a24f88c55d0e110b06a38c9314f8b9541aa6f360
Merge: 8718e47 d911fbc
Author: Hui.Chen <[email protected]>
Date:   Mon Dec 21 22:18:04 2015 +0800


    Merge branch 'feature-update' of git.qyidea.com:hui.chen/hearthdap-front


commit 8718e475ce892ddecedf5cadd810d36ca2473a22
Author: Hui.Chen <[email protected]>
Date:   Mon Dec 21 22:13:52 2015 +0800


    modify user info ajax interface to handle response


commit d911fbc1834f12d58420e8f061b9804e8750df42
Author: sunjiahe <[email protected]>
Date:   Mon Dec 21 20:13:57 2015 +0800


    modify the function getDeckStatus


commit 35b40be45c2c2e97f30f1d838e4a5d74214c83d1
Author: sunjiahe <[email protected]>
Date:   Mon Dec 21 16:22:47 2015 +0800


    modify potential bugs


commit 822bc656c705464de57e36bc0c21212331a43b15
Author: sunjiahe <[email protected]>
Date:   Mon Dec 21 15:24:36 2015 +0800


    modify a description of a function


commit 48e2ddc5e3df2640bc8a004df78a3d2953df0a29
Author: sunjiahe <[email protected]>
Date:   Mon Dec 21 14:58:46 2015 +0800


    get data with deck id and time span


commit c858ae1d6b8aac54cbed9dc6edb5b121fcc2a598
Merge: 1b50079 58cd4f2
Author: Hui.Chen <[email protected]>
Date:   Mon Dec 21 13:44:31 2015 +0800


    Merge branch 'feature-update' of git.qyidea.com:hui.chen/hearthdap-front


commit 1b500792ba2ae9bdc2b2a6e4b7203e6ec0b877cd
Author: Hui.Chen <[email protected]>


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git commit -m "add index of help"
[guoxun f3790fd] add index of help
 3 files changed, 496 insertions(+)
 create mode 100644 application/controllers/helpIndex.php
 create mode 100644 application/views/helpIndex.tpl
 create mode 100644 assets/images/helpView.jpg


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch
* guoxun
  master


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch -a
* guoxun
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature-update
  remotes/origin/guoxun
  remotes/origin/master


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git log
commit f3790fd13a597e61b8316bfcd51b9acd2fe920d3
Author: guoxun <[email protected]>
Date:   Mon Mar 7 17:00:23 2016 +0800


    add index of help


commit f258c36490d35ff956d47956bfb67bfc45eaf940
Merge: d1a272e 30ae67c
Author: Hui.Chen <[email protected]>
Date:   Thu Jan 14 16:32:26 2016 +0800


    Merge branch 'dev' of git.qyidea.com:hui.chen/hearthdap-front


commit d1a272e9d568c5f60c0e1f5eda76765d5d67c090
Author: Hui.Chen <[email protected]>
Date:   Thu Jan 14 16:31:22 2016 +0800


    remove authorized_keys


commit 30ae67c27ccb6e72552e8f08f51e69de0125bef0
Author: sjh <[email protected]>
Date:   Tue Jan 12 16:21:11 2016 +0800


:


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git push origin guoxun
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 94.23 KiB | 0 bytes/s, done.
Total 10 (delta 6), reused 0 (delta 0)
To [email protected]:hui.chen/hearthdap-front.git
   f258c36..f3790fd  guoxun -> guoxun


二.解决远端冲突问题:

1.这里有个暴力解法 在保证你本地已经是你当前所需的结果,那么可以直接删除远端。

http://git.qyidea.com/hui.chen/hearthdap-front/branches

在这个网站上直接删除了远端分支,解决了问题· 也可以用 git push origin :guoxun 来删除远端 本质上,不是删除,是覆盖远端。

操作记录如下:

admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
nothing to commit, working directory clean


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git push origin guoxun
To [email protected]:hui.chen/hearthdap-front.git
 ! [rejected]        guoxun -> guoxun (non-fast-forward)
error: failed to push some refs to '[email protected]:hui.chen/hearthdap-front.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
nothing to commit, working directory clean


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git log
commit c23dfd60efbea5fff0dcf2bfc6d75067e78b8d9b
Author: guoxun <[email protected]>
Date:   Sat Mar 12 18:35:44 2016 +0800


    add function email expression test


commit 849c3d30fe87bbe843a8c9ac5e1ec6aea903e3fc
Author: guoxun <[email protected]>
Date:   Fri Mar 11 23:27:48 2016 +0800


    add function register


commit 07efb997eb1e3835abee98dcba4a0f5cfc2397c8
Author: guoxun <[email protected]>
Date:   Tue Mar 8 13:02:18 2016 +0800


    add help index by modal


commit c5098e76102be9af515b1503bdc5ca20585726f7
Author: guoxun <[email protected]>
Date:   Tue Mar 8 00:12:07 2016 +0800


    debug index of help


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git status
On branch guoxun
nothing to commit, working directory clean


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git fetch


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch -a
* guoxun
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/feature-update
  remotes/origin/guoxun
  remotes/origin/master
  remotes/origin/sjhtest


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch -a
* guoxun
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/feature-update
  remotes/origin/guoxun
  remotes/origin/master
  remotes/origin/sjhtest


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch -a
* guoxun
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/feature-update
  remotes/origin/guoxun
  remotes/origin/master
  remotes/origin/sjhtest


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git push origin :guoxun
error: unable to delete 'guoxun': remote ref does not exist
error: failed to push some refs to '[email protected]:hui.chen/hearthdap-front.git'


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git branch -a
* guoxun
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/feature-update
  remotes/origin/guoxun
  remotes/origin/master
  remotes/origin/sjhtest


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ git push origin guoxun
Counting objects: 38, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (38/38), done.
Writing objects: 100% (38/38), 182.73 KiB | 0 bytes/s, done.
Total 38 (delta 29), reused 0 (delta 0)
To [email protected]:hui.chen/hearthdap-front.git
 * [new branch]      guoxun -> guoxun


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$ ^C


admin@guoxun MINGW64 /guoxungit/hearthdap-front (guoxun)
$

你可能感兴趣的:(git)