“Git基础及常用命令”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
第37行: 第37行:
 
git remote add origin [email protected]:evan886/learn-english.git
 
git remote add origin [email protected]:evan886/learn-english.git
 
git push -u origin master
 
git push -u origin master
 +
 +
…or import code from another repository
 +
 +
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
  
 
</pre>
 
</pre>

2020年10月20日 (二) 01:50的版本

常用命令

日常使用

Git五分钟教程



添加 key 后 clone 

#配置 
 git config --global user.name "evan886"
  git config --global user.email "[email protected]"


#日常用得最多就这几个了
git pull origin master
git add youfile 
git commit -m " "
git push origin master

note 
当我们修改了很多文件,而不想每一个都add,想commit自动来提交本地修改,我们可以使用-a标识。

git commit -a -m "Changed some files"


有时提交不成 冲突了 请用 git rm -f  filename

…or create a new repository on the command line
echo "# learn-english" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:evan886/learn-english.git
git push -u origin master

…or push an existing repository from the command line
git remote add origin [email protected]:evan886/learn-english.git
git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

打标签

在Git中打标签非常简单,首先,切换到需要打标签的分支上:

$ git branch
* dev
  master
$ git checkout master
Switched to branch 'master'
然后,敲命令git tag <name>就可以打一个新标签:

$ git tag v1.0
可以用命令git tag查看所有标签:

$ git tag
v1.0

git将本地代码提交到远程仓库

#以我的i3wm配置文件作例子
# create a new repository on the command line
echo "# myi3" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:evan886/myi3.git
git push -u origin master

git将本地代码提交到远程仓库

git分支的合并

在git中,可以使用git merge 和git rebase两个命令来进行分支的合并

git分支的合并

usage first

添加key后 


#配置 
 git config --global user.name "evan886"
  git config --global user.email "[email protected]"


git 基础安装使用

git 服务器搭建




服务器上 

apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
  libz-dev libssl-dev

apt-get install git

 git --version
git version 2.20.1





 使用我们指定目录作为Git仓库。

git init newrepo
useradd git #也可以让这个用户不可以登录,为了安全嘛


#试过 这个是成功的 

mkdir  testrepo

root@cailuw-test:/data# chown -R git.git testrepo/
root@cailuw-test:/data# cd testrepo/
root@cailuw-test:/data/testrepo# git init --bare test.git 
Initialized empty Git repository in /data/testrepo/test.git/

以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:
root@cailuw-test:/data/testrepo# chown -R git.git test.git/

#添加key 
mkdir /home/git/.ssh -p
cp /root/.ssh/authorized_keys /home/git/.ssh/

chown -R git.git /home/git/.ssh/authorized_keys




 client  在你的 客户端机器上
 
 
 ssh  -T  git账号名@服务器IP  #客户端验证连接
 ssh -T [email protected]

git clone [email protected]:/data/testrepo/test.git 
正克隆到 'test'...
warning: 您似乎克隆了一个空仓库。


#配置 
 git config --global user.name "evan886"
  git config --global user.email "[email protected]"

Git 服务器搭建 在CentOS/RHEL上源码或者 yum 安装Git 以及 linux and win client 使用

Git本地远程仓库的搭建(局域网内也可提交)

Git本地仓库的搭建及使用

[https://blog.csdn.net/qq_33598419/article/details/94392074?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param 使用Git搭建自己的私有/个人Git仓库 ]

http://blog.linuxchina.net/2015/06/18/how-to-use-git-%e8%bd%ac/

git usage on win


#git init 

git config --global --edit 

配置为你的用户和用户名

# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
        name = evan
        email = [email protected]

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

日常用得最多就这几个了
git pull origin master
git add youfile 
 git commit -m " "
 git push origin master

[Win-1.lxtx_fengjw] ➤ git push
Username for 'http://gitlab.net':
Password for 'http://[email protected]':
To http://gitlab.net/lxtx-backend-docs/docs.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://gitlab.net/lxtx-backend-docs/docs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.





Git自动账号密码填充

1、每次操作都需要输入用户名和密码感觉很繁琐,解决方法,在本地的工程文件夹的.git下打开config文件添加:

[credential]
     helper = store或者在git bash 中执行
git config --global credential.helper store再输入一次用户名密码后就可以保存住了。

2、不行就用以下方法:
先用Git拉一次东西,拉的时候会提醒你输入帐号的密码
输入正确的帐号和密码后,等东西拉完以后输入
git config --global credential.helper store



#这样只针对单个project
[remote "origin"]
    url = http://huangweiqing:[email protected]/zt_tech/_interface.git 


see also

廖Git教程

GitLab使用教程

GIT 常用命令

Git & Gitlab 使用指南

GitLab的简单使用

Git完成HTTPS的自动账号密码填充

git clone代码提示需要输入密码

删除git中缓存的用户名和密码


https://help.github.com/cn


Git 基础 - 打标签

创建标签

git 解决冲突

git创建一个自己的本地仓库