第一次用git 和手册

Git操作指南
一,git clone git@xxx.xxx.xx:quark/fouge.git
出现permission denied

解决方式:
1. ssh-keygen -t rsa 会生成两个文件 id_rsa, id_rsa.pub
2. 把id_rsa.pub里的东西添加到git account里的SSH Public Keys。

二,然后输入passpharse,git clone ....


如果git push出现:
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated. This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning: 'nothing' : Do not push anything
warning: 'matching' : Push all matching branches (default)
warning: 'tracking' : Push the current branch to whatever it is tracking
warning: 'current' : Push the current branch

增加一个配置
git config push.default current

下面文档来源于:
http://hi.chinaunix.net/?21747227/viewspace-42437

流程:取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器
取代码及修改全局设置

设置用户名与邮箱

git config--global user.name"My Name"
git config--global user.email"my@email.com"

从已有的git库中提取代码
git clone git@server:app.git

每次更改代码的操作
更新本地代码到最新版本(需要merge才能合到本地代码中)
git fetch

合并更新后的代码到本地
git merge

更新代码方式的另一种方法(git pull是git fetch和git merge命令的一个组合)
git pull

修改代码后,查看已修改的内容
git diff--cached

将新增加文件加入到git中
git add file1

从git中删除文件

git rm file1
git rm-r dir1

提交修改

git commit-m'this is memo'

如果想省掉提交之前的 git add 命令,可以直接用

git commit-a -m'this is memo'

commit和commit -a的区别, commit -a相当于:

* 第一步:自动地add所有改动的代码,使得所有的开发代码都列于index file中

* 第二步:自动地删除那些在index file中但不在工作树中的文件

* 第三步:执行commit命令来提交

提交所有修改到远程服务器,这样,其它团队成员才能更新到这些修改

git push

其它常用命令

显示commit日志
git log

不仅显示commit日志,而且同时显示每次commit的代码改变。
git log -p

回滚代码:

git revert HEAD

你也可以revert更早的commit,例如:

git revert HEAD^

将branch name分支合并到当前分支中。(如果合并发生冲突,需要自己解决冲突)

git merge branchname

解决冲突

当merge命令自身无法解决冲突的时候,它会将工作树置于一种特殊的状态,并且给用户提供冲突信息,以期用户可以自己解决这些问题。当然在这个时候,未发生冲突的代码已经被git merge登记在了index file里了。如果你这个时候使用git diff,显示出来的只是发生冲突的代码信息。

在你解决了冲突之前,发生冲突的文件会一直在index file中被标记出来。这个时候,如果你使用git commit提交的话,git会提示:filename.txt needs merge

在发生冲突的时候,如果你使用git status命令,那么会显示出发生冲突的具体信息。

在你解决了冲突之后,你可以使用如下步骤来提交:

第一步(如果需要增加文件):

git add file1

第二步:

git commit
### 首次安装并配置 Git #### 一、下载并安装 Git 在开始使用 Git 管理项目的版本之前,需要将它安装到计算机上。可以通过以下方式下载并安装 Git: - **Windows 系统**:访问 [Git 官方下载页面](https://git-scm.com/downloads) 下载安装包。安装完成后,可以在 **Git Bash** 或 **命令行工具** 中使用 Git 命令。 - **Mac 系统**:可以使用 `Homebrew` 安装 Git,运行命令 `brew install git`。也可以访问 [Git 官方下载页面](https://git-scm.com/downloads) 下载 Mac 版本的安装包进行安装。 - **Linux 系统**:可以使用包管理器安装 Git,例如在 Ubuntu 上运行 `sudo apt-get install git`,或者在 Fedora 上运行 `sudo dnf install git`。 #### 二、配置用户信息 安装完 Git 之后,要做的第一件事就是设置自己的用户名邮件地址。因为通过 Git 对项目进行版本管理的时候,Git 需要使用这些基本信息,来记录是谁对项目进行了操作。 可以通过以下命令配置全局用户名邮箱: ```bash git config --global user.name "Your Name" git config --global user.email "you@example.com" ``` 如果使用了 `--global` 选项,那么该命令只需要运行一次,即可永久生效。这些配置信息会被写入到 Git 的全局配置文件中。 #### 三、Git 的全局配置文件 通过 `git config --global user.name` `git config --global user.email` 配置的用户名邮箱地址,会被写入到 `C:/Users/用户名文件夹/.gitconfig` 文件中(Windows)或 `~/.gitconfig` 文件中(Mac Linux)。这个文件是 Git 的全局配置文件,配置一次即可永久生效。可以使用文本编辑器打开此文件,从而查看自己曾经对 Git 做了哪些全局性的配置。 #### 四、检查配置信息 除了使用文本编辑器查看全局的配置信息之外,还可以运行如下的终端命令,快速查看 Git 的全局配置信息: - 查看所有全局变量:`git config --list --global` - 查看指定的全局变量: - `git config user.name` - `git config user.email` #### 五、获取帮助信息 可以使用 `git help <verb>` 命令,无需联网即可在浏览器中打开帮助手册。如果不想查看完整的手册,可以用 `-h` 选项获得更简明的“help”输出。例如: ```bash git help config git config -h ``` #### 六、生成 SSH 密钥并配置远程仓库 如果你计划将代码提交到远程仓库(如 GitHub 或 Gitee),还需要生成 SSH 密钥并将其添加到远程仓库中: 1.Git Bash 或终端中运行以下命令生成 SSH 密钥: ```bash ssh-keygen -t rsa -b 4096 -C "you@example.com" ``` 按照提示操作,可以直接按回车键使用默认路径空密码。 2. 生成密钥后,使用以下命令查看公钥内容: ```bash cat ~/.ssh/id_rsa.pub ``` 3. 将公钥内容复制到远程仓库的 SSH 密钥管理页面。例如: - Gitee:[https://gitee.com/profile/sshkeys](https://gitee.com/profile/sshkeys) - GitHub:[https://github.com/settings/keys](https://github.com/settings/keys) 4. 测试 SSH 连接: ```bash ssh -T git@github.com ``` #### 七、克隆远程仓库 配置完成后,可以通过以下命令克隆远程仓库到本地: ```bash git clone git@github.com:username/repository.git ``` 替换 `username` `repository` 为你自己的用户名仓库名称。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值