Precautions
写在前面
- Git Bash replication (ctrl + ins), paste (shift + ins)
- When you paste an absolute path, use / instead of \
- When the Linux command git used in the Linux command, the console does not return then there is no problem
- clear clear screen
First, establish a remote warehouse
- Create a new warehouse in the Github, used to store the new project
- Edit the name and description warehouse
-
The new warehouse was completed completed
Warehouse attention here to get to the end of the address .git
Second, establish a local staging area
cd 路径 //进入当前目录
git init //在本地对当前项目进行初始化(建立一个暂存区)
At this point .git generate a hidden file in the current directory, then the virtual warehouse built in memory to complete
all versions of .git file is stored in the current project information
Third, the documents submitted
3.1 Workspace -> staging area
$ git add 文件名 //提交指定的文件
$ git add * //提交所有文件
$ git commit -m "描述" //本次提交的描述
After the completion of the filing, may be checked by looking at the status of the current work area if the submission is successful
git status // view the current status of the work area
Showing results (two kinds of demerits)
- There is no submission
- There is uncommitted file (the file is modified)
3.1.1 recover files from a staging area to the work area
情景:当文件提交到暂存区后,工作区的文件丢失,需要从暂存区恢复文件到工作区
git checkout // filename to restore files from the staging area to the work area
git diff // before the file submitted to the staging area to view specific content file modification
git log // View historical version has been submitted to the temporary area
3.1.2 restore files to a specific version
command | Explanation | Remark |
---|---|---|
$ git reset --hard HEAD^ | Fall back to the previous version | |
$ git reset --hard HEAD^^ | Fall back on two versions | |
$ Git reset --hard version number | Falls back to the specified version | The version number is later commit a string |
3.2 staging area -> remote repository
3.2.1 Get the address of the remote repository
Only authorized computers can GitHub project submitted to the remote repository
is not any computer can easily submit, the computer needs to be treated github submitted authorize
this authorization is done through the SSH key
3.2.1 get ssh key
ssh-keygen -t rsa -C "邮箱"
[Note] It should knock three times Enter
Find windows computer files: My Computer => Users => username folder => .ssh (hidden files) => xxx.pub
.pub file in there that we need key
3.2.2 Key configuration in the GitHub
At this time, a new key may be selected, and can fill key
3.3 staging area -> remote repository
回到 Git Bash
$ git remote add origin 仓库地址
$ git push -u origin master
//这里的仓库地址是前面新建原程仓库时,以 .git 结尾的那个地址
After waiting to submit complete
Fourth, the problems encountered when using git
problem | Possible solutions |
---|---|
git报错:'fatal: remote origin already exists. | Solution |
vscode display is not installed git | Solution |