Git tutorial and problem analysis


 This article is from http://blog.csdn.net/liuxian13183/  , and the reference must be indicated!


Git Tutorial


I have used Git a lot recently, so I made a tutorial for your reference.


1. Install Git and configure environment variables

2. Configure username, email

3. Switch to the working directory, download the source code, first execute git init to initialize an environment, and then


4. Modify and push to the local, and finally push to the remote


5. Others, Git is a distributed tool. Everyone's computer is a warehouse. Everyone exchanges files through the local area network to achieve the purpose of collaborative office.

Order:
git reset --hard commitId rollback commitId this commit
git branch dev If there is none, it will be generated, and if there is, the branch dev will be deleted
git branch View local branch
git remote View remote branches –v for more detailed information
git checkout dev to switch to the dev file
git rm build.gradle deletes the build.gradle file locally
git status View the status of the working directory, whether there are deletions or uncommitted, etc.
git checkout build.gradle restores the build.gradle file locally
git log View push commit log
cat filename new file
:q Exit the operation after entering the Vim command
git checkout dev to switch to the dev file
git checkout –b dev Create if nothing, switch to the dev file
git merge dev merge dev branch modifications (git pull origin dev is also feasible)
git branch -d dev delete the dev branch
git stash saves the scene and cuts the branch from master to fix bugs
git stash list which stash is saved
git stash apply restore drop delete
git stash pop restore and delete
git push origin master/dev pushes local to remote
The feature is the same as the branch function, mainly for developing new functions.
Example of usage:
git checkout –b feature-Iot新建feature
git checkout –d feature-Iot 删除feature
git tag 列出所有tag
git tag v1.0 –m “v1.0” 打1.0的tag
git push origin v1.0 推送分支到远程
git tag –d v1.0 本地删除tag
git push origin :refs/tags/v1.0
-d 删除
 -m 加标签
拉一个tag的代码  git clone --branch v1.6.5.7 https://github.com/ManaPlus/ManaPlus.git
6、        本地项目首次加入Git管理---慎用!!!

Git push –u origin master

7、        修改远程项目为本地项目---慎用!!!

将目标项目拷贝到当前文件夹

Git init

Git pull

删除本地的远程项目

添加并提交到远程

完成本次操作。


问题1:git clone/pull时,出现Permission Denied。

回答:主要问题1、在于权限未配置,请联系项目Owner配置权限;2、将本地.ssh文件夹中的id.rsa配置到远程的SSH的Keys下面;3、本地存在github账号,与公司项目冲突,使得Git.bash不清楚你要使用哪方的账号信息,那么需要在.ssh目录下加入一个config文件,并将如下信息配置(原理如DNS):

# gitlab
Host gitlab.YourCompany.com
HostName gitlab.YourCompany.com
User [email protected]
IdentityFile ~/.ssh/id_rsa
Port YourServerCode 如8090


生成rsa文件

ssh-keygen -t rsa -C "youremail"


问题2:通过TortoiseGit来拉代码,出现让输入密码,无论怎么输入或正确密码,均不能通过

回答:原因在于在user目录下的.ssh文件夹生成,如果无则不会出现;TortoiseGit使用putty来拉,此时缺少ppk文件,需要使用puttygen.exe来使用id_rsa文件生成新的ppk文件,generate-save private key即可。最后把此文件加入设置进来,如下图-右键git clone,选择Load Putty Key选项即可


问题3、fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.


Please make sure you have the correct access rights
and the repository exists.

解决方案:

1、查看配置 cat $(git rev-parse --show-toplevel)/.git/config

2、git remote add origin "url.git"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325986070&siteId=291194637