Git入门初探三[待完善]
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ gti statud
bash: gti: command not found
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ gti status
bash: gti: command not found
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ cat readme.txt
Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git commit -m "git tracks change"
[master 332319e] git tracks change
1 file changed, 2 insertions(+), 1 deletion(-)
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
diff
index cbfb4b1..636cfcc 100644
+++ b/readme.txt
@@ -1,4 +1,4 @@
Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
-Git tracks changes.
\ No newline at end of file
+Git tracks changes of files.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ cat readme.txt
Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git commit -m "second commit"
[master 623338c] second commit
1 file changed, 1 insertion(+), 1 deletion(-)
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
diff
index 636cfcc..4019639 100644
+++ b/readme.txt
@@ -2,3 +2,4 @@ Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
+My stupid boss still prefers SVN.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git checkout
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
diff
index 636cfcc..830f4a4 100644
+++ b/readme.txt
@@ -2,3 +2,4 @@ Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
+My stupid boss still prefers SVN.
\ No newline at end of file
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git reset HEAD readme.txt
Unstaged changes after reset:
M readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git diff HEAD
diff
index 636cfcc..830f4a4 100644
+++ b/readme.txt
@@ -2,3 +2,4 @@ Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
+My stupid boss still prefers SVN.
\ No newline at end of file
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git reset head readme.txt
Unstaged changes after reset:
M readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git stuts
git: 'stuts' is not a git command. See 'git
The most similar command is
status
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
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: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ cat readme.txt
Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
My stupid boss still prefers SVN.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git checkout
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ cat readme.txt
Git is a distributed version control system,
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add test.txt
fatal: pathspec 'test.txt' did not match any files
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ^C
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ll
total 2
-rw-r
-rw-r
-rw-r
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ commit -m test.txt
bash: commit: command not found
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git commit -m test.txt
[master be55322] test.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ rm test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git commit
On branch master
Changes not staged for commit:
deleted: test.txt
no changes added to commit
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git rm test.txt
LICENSE.txt readme.txt test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git rm test.txt
rm 'test.txt'
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git commit -m 'remove test.txt'
[master a61db02] remove test.txt
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 test.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oiPFHw1DJbAXz8s4rlp1YYZ16sJliqUBjSKKOYoMKAo Administrator@ICOS-20180710CX
The key's randomart image is:
+
| .o..+.o . |
|o ...o B o |
|=o o * X |
|E . B & o |
|O. = X S |
|+. . = * |
| . + o |
| o o |
| ... |
+
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ll
total 2
-rw-r
-rw-r
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ls -s
total 2
1 LICENSE.txt 1 readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ls -a
./ ../ .git/ LICENSE.txt readme.txt
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ll -ah
total 10K
drwxr-xr-x 1 Administrator 197121 0 8月 25 13:47 ./
drwxr-xr-x 1 Administrator 197121 0 8月 25 12:00 ../
drwxr-xr-x 1 Administrator 197121 0 8月 25 13:48 .git/
-rw-r
-rw-r
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ cd /c/Users/Administrator/.ssh
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$ ll
total 5
-rw-r
-rw-r
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzbOSq8+LWWMML6xtlr7LQORZVba++gpRpdlnDy5D/dRWhLEbKcM0xwHppdzJOishJ5sDkpQbrRo/tx6KspK3uinI97HS9YgNBsydHxVzCOqHOPthfUNlaepKjv0seWOdzdfszws/sm22xOp2H1vRq/O6xnYh5fjpVHyYQk29ThwYh49OSb3ZJQiPvxUO2pZkVMBOy5l7p89PwbTlsg95iEHuctug0NzZ3z7hMBRFGnHhoUABGVpwPOSwalws0guAAgtWE0S5u7QC1MBnlh1dhpIikOtlxqeCxL1d5Tlm9+Wlqy5FiB2H5MB9bCpVcSr8+Ndj1PfSiGud6u6GhEvZ7 Administrator@ICOS-20180710CX
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$ git remote add origin https://github.com/LittleLawson/learnGit.git
fatal: Not a git repository (or any of the parent directories): .git
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$ git push -u origin master^C
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$
Administrator@ICOS-20180710CX MINGW64 ~/.ssh
$ cd /g/learnGit/
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ ll
total 2
-rw-r
-rw-r
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git remote add origin https://github.com/LittleLawson/learnGit.git
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': 1471831539@qq.com
9297remote: Permission to LittleLawson/learnGit.git denied to liu16659.
fatal: unable to access 'https://github.com/LittleLawson/learnGit.git/': The requested URL returned error: 403
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git remote add origin https://github.com/LittleLawson/learnGit.git
fatal: remote origin already exists.
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git push -u origin master
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git remote rm orgin
fatal: No such remote: orgin
Administrator@ICOS-20180710CX MINGW64 /g/learnGit (master)
$ git remote -v
origin https://github.com/LittleLawson/learnGit.git (fetch)
origin https://github.com/LittleLawson/learnGit.git (push)
要关联一个远程库,使用命令git remote add origin git@server-name:path/repo-name.git;
关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;
如果使用git push -u origin master之后,会弹出GitHub登录框的话,说明你没有使用ssh 功能。使用以下方式即可解决【前提是需要有一个事先生成ssh秘钥】:
git remote rm origin
git remote add origin git@github.com:username/repository.git
git push -u origin master