git服务器的搭建及使用 (2)

Git rm -cached file 将文件从暂存区转成未暂存,从版本库中删除,但不能删除工作目录的该文件,即文件恢复不追踪状态。  都是算是改动,commit才算是真改动。

###创建一个新的文件

[root@localhost ~]# echo "python" > python.htm

[root@localhost ~]# git add python.htm

[root@localhost ~]# git commit -m "add python"

[master 50e12c9] add python

Committer: root <root@localhost.localdomain>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"

git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

git commit --amend --author=\'Your Name <you@example.com>\'

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 python.htm

[root@localhost ~]# git log

commit 50e12c9e4dd5928dbaf14b647bccd954293ff5e6

Author: root <root@localhost.localdomain>

Date:   Tue May 22 09:21:17 2018 +0800

add python

commit 1ed76cf5c048bfeef64916ffa4d66abdc81fd55f

Author: root <root@localhost.localdomain>

Date:   Tue May 22 08:58:00 2018 +0800

No3 commit

commit ab76fd902da7168e69b2ca1152373c9c571e7045

Author: root <root@localhost.localdomain>

Date:   Mon May 21 20:11:18 2018 +0800

2 No2 commit

commit 584479710780dc2069751636c1d27f2233abfc4b

Author: root <root@localhost.localdomain>

Date:   Mon May 21 20:05:51 2018 +0800

1 No1 commit

###2mv

[root@localhost ~]# git mv python.htm python.py

[root@localhost ~]# git commit -m "my python"

[master 30cd6ee] my python

Committer: root <root@localhost.localdomain>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"

git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

git commit --amend --author=\'Your Name <you@example.com>\'

1 files changed, 0 insertions(+), 0 deletions(-)

rename python.htm => python.py (100%)

###3rm

rename python.htm => python.py (100%)

[root@localhost ~]# echo "print("hello python")" > python.py

[root@localhost ~]# git add python.py

[root@localhost ~]# git diff -cached

error: invalid option: -cached

[root@localhost ~]# git diff --cached

diff --git a/python.py b/python.py

index fdc793e..a280d44 100644

--- a/python.py

+++ b/python.py

@@ -1 +1 @@

-python

+print(hello python)

[root@localhost ~]# git rm --cached python.py

rm \'python.py\'

[root@localhost ~]# git diff --cached

diff --git a/python.py b/python.py

deleted file mode 100644

index fdc793e..0000000

--- a/python.py

+++ /dev/null

@@ -1 +0,0 @@

-python

[root@localhost ~]# git commit -m "delete python"

[master 501fec3] delete python

Committer: root <root@localhost.localdomain>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"

git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

git commit --amend --author=\'Your Name <you@example.com>\'

1 files changed, 0 insertions(+), 1 deletions(-)

delete mode 100644 python.py

[root@localhost ~]# ls

about.htm

anaconda-ks.cfg

Desktop

Documents

Downloads

git-2.16.3-intel-universal-mavericks.dmg

gogs.script

index.htm

install.log

install.log.syslog

Music

Percona-Server-5.5.45-37.4-r042e02b-el6-x86_64-bundle.tar

Percona-Server-55-debuginfo-5.5.45-rel37.4.el6.x86_64.rpm

Percona-Server-client-55-5.5.45-rel37.4.el6.x86_64.rpm

Percona-Server-devel-55-5.5.45-rel37.4.el6.x86_64.rpm

Percona-Server-server-55-5.5.45-rel37.4.el6.x86_64.rpm

Percona-Server-shared-55-5.5.45-rel37.4.el6.x86_64.rpm

Percona-Server-test-55-5.5.45-rel37.4.el6.x86_64.rpm

Pictures

Public

python.py

Templates

Videos

[root@localhost ~]# git status

# On branch master

# Untracked files:

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

#

#       .ICEauthority

#       .Xauthority

#       .abrt/

#       .bash_history

#       .bash_logout

#       .bash_profile

#       .bashrc

#       .cache/

#       .config/

#       .cshrc

#       .dbus/

#       .esd_auth

#       .gconf/

#       .gnome2/

#       .gnote/

#       .gnupg/

#       .gtk-bookmarks

#       .imsettings.log

#       .local/

#       .mysql_history

#       .pulse-cookie

#       .pulse/

#       .tcshrc

#       .viminfo

#       Percona-Server-5.5.45-37.4-r042e02b-el6-x86_64-bundle.tar

#       Percona-Server-55-debuginfo-5.5.45-rel37.4.el6.x86_64.rpm

#       Percona-Server-client-55-5.5.45-rel37.4.el6.x86_64.rpm

#       Percona-Server-devel-55-5.5.45-rel37.4.el6.x86_64.rpm

#       Percona-Server-server-55-5.5.45-rel37.4.el6.x86_64.rpm

#       Percona-Server-shared-55-5.5.45-rel37.4.el6.x86_64.rpm

#       Percona-Server-test-55-5.5.45-rel37.4.el6.x86_64.rpm

#       anaconda-ks.cfg

#       git-2.16.3-intel-universal-mavericks.dmg

#       gogs.script

#       install.log

#       install.log.syslog

#       python.py

nothing added to commit but untracked files present (use "git add" to track)

[root@localhost ~]#

12)push到服务器

本地搭建私服,模仿GitHub

配置本地用户名和邮箱:

[root@localhost ~]# git config --global user.name "myself"

[root@localhost ~]# git config --global user.email "myself@qq.com"

[root@localhost ~]#

[root@localhost ~]# cat ~/.gitconfig

[user]

name = myself

email = myself@qq.com

关联远程版本库:

[root@localhost ~]# git remote add origin :3000/myself/test.git

[root@localhost ~]# cat ~/.gitconfig

[user]

name = myself

email = myself@qq.com

[root@localhost ~]# cat .git/config

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

[remote "origin"]

url = :3000/myself/test.git

fetch = +refs/heads/*:refs/remotes/origin/*

远程版本库名origin,这是一个习惯用法,将建立origin和后面的URL映射,这些信息都保存在.git/config 文件中的[remote "origin"]中。

推送数据:

[root@localhost ~]# git push -u origin master

error: The requested URL returned error: 401 Unauthorized while accessing :3000/myself/test.git/info/refs

fatal: HTTP request failed

通讯失败解决办法:vi .git/config

里面url里面加入一个用户名。

[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

[remote "origin"]

url = @192.168.142.128:3000/myself/test.git

fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

remote = origin

merge = refs/heads/master

[root@localhost ~]# git push -u origin master

Xlib:  extension "RANDR" missing on display "localhost:10.0".

error: The requested URL returned error: 401 while accessing @192.168.142.128:3000/myself/test.git/info/refs

fatal: HTTP request failed

[root@localhost ~]# git push -u origin master

Xlib:  extension "RANDR" missing on display "localhost:10.0".

Counting objects: 16, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (10/10), done.

Writing objects: 100% (16/16), 1.21 KiB, done.

Total 16 (delta 3), reused 0 (delta 0)

To @192.168.142.128:3000/myself/test.git

* [new branch]      master -> master

Branch master set up to track remote branch master from origin.

输入密码就能连接到远程仓库了。私有的仓库必须登录,只能用户自己看。

-u 第一次推送的时候加上,以后就不需要-u参数,可以使用git origin master或者git push就可以了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zggpyx.html