git 初步

Posted Arlenmbx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git 初步相关的知识,希望对你有一定的参考价值。

git command help

不知道自己怎么搞的,发现了查看git命令的详细文档的一个操作

git *** --hep就可以生成对应的html文档

eg: git config --help / git commit -help

效果图如下

 

 

 

git 版本控制管理

之前并没有接触过git方面的知识,在阿里实习期间才接触到git的管理流程,当时对git一无所知,师姐耐心的手把手的教我怎么使用,惭愧惭愧,在这里首先感谢我的师姐对我的帮助,之后恶补了一堆git快速入门教程,才得以在实习中有了一些进展,这几天事情不多,正好get了一本详细的git书籍,开始系统的学习了一下git

首先我是使用的windows下的git bash进行的操作,当然感觉cygwin也是不错的选择,但是自我实践,在我的电脑上git bash命令行的反应速度超级慢(延时5s~10s),网上说是os 的io缓存造成的,还有说仓库太大,还需要把360,管家等垃圾软件退了,还有更可笑的解释是时间长了就不慢了(2333),反正解决方案试了很多,没有效果,但是cygwin的反应速度特别快。但是个人还是喜欢使用git bash,because在操作的过程中发现cygwin对命令的支持程度不及git bash (eg : ll  ls -l    )

first 我在~目录下建立了一个目录,作为初始版本库开始进行操作

mkdir ~/public_html

cd ~/public_html

touch index.html

echo "balabala..." > index.html

git init

这样便生成了隐藏文件.git

很多配置信息都存储在.git中,这个只是针对这个版本库的配置,当然也有用户级别和系统级别的config,用户级别的放在~/.gitconfig,需要通过git --global进行配置,系统级别的我暂时没有找到,因为还没有使用到,参考资料说在/etc/gitconfig or /usr/local/etc/gitconfig,感觉在ubuntu或者debian等正常的操作系统下比较正常吧,git bash和cygwin都没有sudo这回事

中途的操作都存在了下面

Administrator@USERCHI-U2H639K MINGW64 ~
$ git status -uno
fatal: Not a git repository (or any of the parent directories): .git

Administrator@USERCHI-U2H639K MINGW64 ~
$ export PATH="$HOME/bin:$PATH"

Administrator@USERCHI-U2H639K MINGW64 ~
$ ll
total 3409
lrwxrwxrwx 1 Administrator 197121      67 十月 10 15:14  「开始」菜单 -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Start Menu\'/
drwxr-xr-x 1 Administrator 197121       0 十月 10 15:14  AppData/
lrwxrwxrwx 1 Administrator 197121      38 十月 10 15:14 \'Application Data\' -> /c/Users/Administrator/AppData/Roaming/
lrwxrwxrwx 1 Administrator 197121      64 十月 10 15:14  Cookies -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Cookies/
drwxr-xr-x 1 Administrator 197121       0 十月 29 14:33  Desktop/
drwxr-xr-x 1 Administrator 197121       0 十月 17 12:28  Documents/
drwxr-xr-x 1 Administrator 197121       0 十月 29 14:47  Downloads/
drwxr-xr-x 1 Administrator 197121       0 十月 10 15:17  Favorites/
drwxr-xr-x 1 Administrator 197121       0 十月 26 16:19  IdeaProjects/
drwxr-xr-x 1 Administrator 197121       0 十月 29 12:13  IntelGraphicsProfiles/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Links/
lrwxrwxrwx 1 Administrator 197121      36 十月 10 15:14 \'Local Settings\' -> /c/Users/Administrator/AppData/Local/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Music/
lrwxrwxrwx 1 Administrator 197121      32 十月 10 15:14 \'My Documents\' -> /c/Users/Administrator/Documents/
lrwxrwxrwx 1 Administrator 197121      74 十月 10 15:14  NetHood -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Network Shortcuts\'/
-rw-r--r-- 1 Administrator 197121 2097152 十月 29 15:30  NTUSER.DAT
-rw-r--r-- 1 Administrator 197121  262144 十月 29 15:30  ntuser.dat.LOG1
-rw-r--r-- 1 Administrator 197121       0 十月 10 15:13  ntuser.dat.LOG2
-rw-r--r-- 1 Administrator 197121   65536 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TM.blf
-rw-r--r-- 1 Administrator 197121  524288 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TMContainer00000000000000000001.regtrans-ms
-rw-r--r-- 1 Administrator 197121  524288 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TMContainer00000000000000000002.regtrans-ms
-rw-r--r-- 1 Administrator 197121      20 十月 10 15:14  ntuser.ini
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Pictures/
lrwxrwxrwx 1 Administrator 197121      74 十月 10 15:14  PrintHood -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Printer Shortcuts\'/
drwxr-xr-x 1 Administrator 197121       0 十月 29 15:21  public_html/
lrwxrwxrwx 1 Administrator 197121      63 十月 10 15:14  Recent -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Recent/
lrwxrwxrwx 1 Administrator 197121      63 十月 10 15:14  SendTo -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/SendTo/
lrwxrwxrwx 1 Administrator 197121      66 十月 10 15:14  Templates -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Templates/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Videos/
cd
Administrator@USERCHI-U2H639K MINGW64 ~
$ cd ~/p
Pictures/    PrintHood/   public_html/

Administrator@USERCHI-U2H639K MINGW64 ~
$ cd ~/public_html/

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 20 十月 29 15:20 index.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git sta
git: \'sta\' is not a git command. See \'git --help\'.

The most similar commands are
        status
        stage
        stash

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   index.html


Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git commit -m "Initial contents of public_html" \\
>    --author="baidu<arlenmbx@163.com>"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account\'s default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got \'Administrator@USERCHI-U2H639K.(none)\')

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git config --global user.email "arlenmbx@163.com"

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git config --global user.name "mubaixu"

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git commit -m "Initial contents of public_html"    --author="baixu <arlenmbx@163.com>"
[master (root-commit) d8d6af9] Initial contents of public_html
 Author: baixu <arlenmbx@163.com>
 1 file changed, 1 insertion(+)
 create mode 100644 index.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ vim
e
Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ export GIT_EDITOR=vim

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git commit -m "Initial contents of public_html"    --author="baixu <arlenmbx@163.com>"
On branch master
nothing to commit, working tree clean

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git status
On branch master
nothing to commit, working tree clean

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 20 十月 29 15:20 index.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ cd .git/

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ ll
total 9
-rw-r--r-- 1 Administrator 197121  32 十月 29 15:43 COMMIT_EDITMSG
-rw-r--r-- 1 Administrator 197121 130 十月 29 15:21 config
-rw-r--r-- 1 Administrator 197121  73 十月 29 15:21 description
-rw-r--r-- 1 Administrator 197121  23 十月 29 15:21 HEAD
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 hooks/
-rw-r--r-- 1 Administrator 197121 145 十月 29 15:34 index
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 info/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 logs/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 objects/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 refs/

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ cd logs/

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git/logs (GIT_DIR!)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 176 十月 29 15:36 HEAD
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 refs/

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git/logs (GIT_DIR!)
$ cd ..

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ ll
total 9
-rw-r--r-- 1 Administrator 197121  32 十月 29 15:43 COMMIT_EDITMSG
-rw-r--r-- 1 Administrator 197121 130 十月 29 15:21 config
-rw-r--r-- 1 Administrator 197121  73 十月 29 15:21 description
-rw-r--r-- 1 Administrator 197121  23 十月 29 15:21 HEAD
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 hooks/
-rw-r--r-- 1 Administrator 197121 145 十月 29 15:34 index
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 info/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 logs/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 objects/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 refs/
cat
Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ cat COMMIT_EDITMSG
Initial contents of public_html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ tmux
bash: tmux: command not found

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ sudo apt-get install tmux
bash: sudo: command not found

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ apt-get install tmux
bash: apt-get: command not found

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ cd /
sudo apt
Administrator@USERCHI-U2H639K MINGW64 /
$ sudo apt-get install tmux
bash: sudo: command not found

Administrator@USERCHI-U2H639K MINGW64 /
$ cd ~

Administrator@USERCHI-U2H639K MINGW64 ~
$ ll
total 3409
lrwxrwxrwx 1 Administrator 197121      67 十月 10 15:14  「开始」菜单 -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Start Menu\'/
drwxr-xr-x 1 Administrator 197121       0 十月 10 15:14  AppData/
lrwxrwxrwx 1 Administrator 197121      38 十月 10 15:14 \'Application Data\' -> /c/Users/Administrator/AppData/Roaming/
lrwxrwxrwx 1 Administrator 197121      64 十月 10 15:14  Cookies -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Cookies/
drwxr-xr-x 1 Administrator 197121       0 十月 29 14:33  Desktop/
drwxr-xr-x 1 Administrator 197121       0 十月 17 12:28  Documents/
drwxr-xr-x 1 Administrator 197121       0 十月 29 14:47  Downloads/
drwxr-xr-x 1 Administrator 197121       0 十月 10 15:17  Favorites/
drwxr-xr-x 1 Administrator 197121       0 十月 26 16:19  IdeaProjects/
drwxr-xr-x 1 Administrator 197121       0 十月 29 12:13  IntelGraphicsProfiles/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Links/
lrwxrwxrwx 1 Administrator 197121      36 十月 10 15:14 \'Local Settings\' -> /c/Users/Administrator/AppData/Local/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Music/
lrwxrwxrwx 1 Administrator 197121      32 十月 10 15:14 \'My Documents\' -> /c/Users/Administrator/Documents/
lrwxrwxrwx 1 Administrator 197121      74 十月 10 15:14  NetHood -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Network Shortcuts\'/
-rw-r--r-- 1 Administrator 197121 2097152 十月 29 15:53  NTUSER.DAT
-rw-r--r-- 1 Administrator 197121  262144 十月 29 15:53  ntuser.dat.LOG1
-rw-r--r-- 1 Administrator 197121       0 十月 10 15:13  ntuser.dat.LOG2
-rw-r--r-- 1 Administrator 197121   65536 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TM.blf
-rw-r--r-- 1 Administrator 197121  524288 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TMContainer00000000000000000001.regtrans-ms
-rw-r--r-- 1 Administrator 197121  524288 十月 10 15:15  NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TMContainer00000000000000000002.regtrans-ms
-rw-r--r-- 1 Administrator 197121      20 十月 10 15:14  ntuser.ini
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Pictures/
lrwxrwxrwx 1 Administrator 197121      74 十月 10 15:14  PrintHood -> \'/c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Printer Shortcuts\'/
drwxr-xr-x 1 Administrator 197121       0 十月 29 15:21  public_html/
lrwxrwxrwx 1 Administrator 197121      63 十月 10 15:14  Recent -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Recent/
lrwxrwxrwx 1 Administrator 197121      63 十月 10 15:14  SendTo -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/SendTo/
lrwxrwxrwx 1 Administrator 197121      66 十月 10 15:14  Templates -> /c/Users/Administrator/AppData/Roaming/Microsoft/Windows/Templates/
drwxr-xr-x 1 Administrator 197121       0 七月 14  2009  Videos/

Administrator@USERCHI-U2H639K MINGW64 ~
$ cd p
bash: cd: p: No such file or directory
cd pu
Administrator@USERCHI-U2H639K MINGW64 ~
$ cd public_html/
ll

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 20 十月 29 15:20 index.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ cd .git/
ll

Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ ll
total 9
-rw-r--r-- 1 Administrator 197121  32 十月 29 15:43 COMMIT_EDITMSG
-rw-r--r-- 1 Administrator 197121 130 十月 29 15:21 config
-rw-r--r-- 1 Administrator 197121  73 十月 29 15:21 description
-rw-r--r-- 1 Administrator 197121  23 十月 29 15:21 HEAD
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 hooks/
-rw-r--r-- 1 Administrator 197121 145 十月 29 15:34 index
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 info/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 logs/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:36 objects/
drwxr-xr-x 1 Administrator 197121   0 十月 29 15:21 refs/
cat c
Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ cat config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
git
Administrator@USERCHI-U2H639K MINGW64 ~/public_html/.git (GIT_DIR!)
$ cd ..

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 20 十月 29 15:20 index.html
vim
Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ gedit index.html
bash: gedit: command not found

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ vim index.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ cat index.html
<html>
        <body>
my website is alive!
</body>
</html>


Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git commit index.html
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory.
[master 8e924a2] Convert to HTML
 1 file changed, 6 insertions(+), 1 deletion(-)

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git log
commit 8e924a2e7275b853ec5f66d128ff2c0933af90b7 (HEAD -> master)
Author: mubaixu <arlenmbx@163.com>
Date:   Sun Oct 29 15:59:06 2017 +0800

    Convert to HTML

commit d8d6af907c50e2f546456d16be603a97da997ea4
Author: baixu <arlenmbx@163.com>
Date:   Sun Oct 29 15:36:01 2017 +0800

    Initial contents of public_html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git show 8e924a2e7275b853ec5f66d128ff2c0933af90b7
commit 8e924a2e7275b853ec5f66d128ff2c0933af90b7 (HEAD -> master)
Author: mubaixu <arlenmbx@163.com>
Date:   Sun Oct 29 15:59:06 2017 +0800

    Convert to HTML

diff --git a/index.html b/index.html
index 8865c96..c9cff2d 100644
--- a/index.html
+++ b/index.html
@@ -1 +1,6 @@
-my website is alive
+<html>
+       <body>
+my website is alive!
+</body>
+</html>
+

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git diff 8e924a2e7275b853ec5f66d128ff2c0933af90b7 d8d6af907c50e2f546456d16be603a97da997ea4
diff --git a/index.html b/index.html
index c9cff2d..8865c96 100644
--- a/index.html
+++ b/index.html
@@ -1,6 +1 @@
-<html>
-       <body>
-my website is alive!
-</body>
-</html>
-
+my website is alive

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git diff 8e924a2e7275b853ec5f66d128ff2c0933af90b7 d8d6af907c50e2f546456d16be603a97da^C


Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ touch poem.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 53 十月 29 15:57 index.html
-rw-r--r-- 1 Administrator 197121  0 十月 29 16:17 poem.html
vim
Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ vim poem.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ cat poem.html
fuck     shit

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git add poem.html poem.html
warning: LF will be replaced by CRLF in poem.html.
The file will have its original line endings in your working directory.

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git add poem.html

Administrator@USERCHI-U2H639K MINGW64 ~/public_html (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>...以上是关于git 初步的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段15——git命令操作一个完整流程

git初步使用

如何管理在每个 git 版本中添加私有代码片段?

使用 Git 来管理 Xcode 中的代码片段

markdown Git代码片段

git初步用法