Common commands for git submission code, code rollback, and multiple ways to add multiple files and folders

Table of contents

1. Review the steps of git submitting code, that is, the order of git submitting code is as follows:

2. How to perform code rollback?

3. How to store/use/delete storage

 4. Does git delete/restore local branches and delete/restore remote branches?

5. How does git abandon local file modifications?

6. How to add multiple files and upload folders under Git code:

(1) Add files

(2) Upload folder


一、复习一下git提交代码的步骤,即git提交代码的顺序如下:

  在git提交代码之前,需要将本地添加的文件,先添加到git本地记录内,在commit时才能同步到远端的暂存区中,最后push,复习一下git提交代码的步骤,即git提交代码的顺序如下:

Basic command: Right-click on the corresponding .git folder to open Git bashHere

A four-step command needs to be executed:

命令1: git add .
命令2: git commit -m '提交的文字描述'
命令3: git pull origin master
命令4: git push -u origin master-test1

switch branch:

Command: git checkout master

Before merging the code, you need to pull it first:

命令: git pull

 After the pull is complete, the code can be merged:

命令: git merge master-test1

After merging the master-test1 branch into the master, push the master to the remote branch:

 命令: git push -u origin master

The above operation has completed the code merger!

2. How to perform code rollback?

1. First pass the command:  git log view all submission records

Find the version number you want to roll back and roll back:

命令: git reset --hard aaadc2232480a3b8105de70e8ce23acf45fa0dc1

3. How to store/use/delete storage

Storage command:

git stash or git stash save "write a note" (recommended)

使用之前通过:

git stash list 查看贮藏的信息

 使用贮藏命令:

git stash apply stash@{0} (指定储藏的应用)

git stash pop (指定的是最近的储藏)

 Delete cached information command:

git stash drop the name of the stash

 4. Does git delete/restore local branches and delete/restore remote branches?

 First cut to the master branch through the command:

git branch -a (查看已有的本地及远程分支)

 Delete local branch:

git branch -D 本地分支名称

 Restoring the local branch:

git checkout -b 恢复的分支名称

 Delete the remote branch:

 git push origin --delete 远程分支名称

 Restoring the remote branch:

直接在恢复的分支上面push到远程即可

.5. How to resolve conflicts

 For example, when we modify the content in master-test1, if we accidentally modify the original code in master, unexpected conflicts may occur when pulling, resulting in the failure to submit the code:

 We can prompt according to the merge file name: by  vim 李凤/index.html viewing the current conflict location

 After manually resolving conflicts, you can proceed with the code merge operation.

 

5. How does git abandon local file modifications?

1.未使用git add 缓存代码  
    1) 放弃某一个本地文件命令: git checkout -- filename  
    2) 放弃所有文件修改命令:  git checkout . 
2. 已使用git add 缓存代码,未使用git commit   
    1)放弃某一个本地文件命令回到git add .之前 :  git reset HEAD filename   
    2)放弃所有文件修改命令回到git add .之前:    git reset HEAD 
3. 已经用 git commit 提交了代码    
    1)回退到上一次commit的状态: git reset --hard HEAD^    
    2)或者回退到任意版本git reset --hard commit id ,
使用git log命令查看git提交历史和commit id  :  git reset --hard commit id

 

6. How to add 多个文件and how to 上传文件夹:

(1) Add files

  1. git add adds multiple files, separated by spaces
git add file1 file2 file3 file4....

 2. Multiple git

git add file1
git add file2
git add file3
...

 3. Add files in the specified directory,
all files in the config directory and subdirectories, and all exe files in the home directory

git add config/*
git add home/*.exe

 4. git add. Add all files, or – all add all files

git add .  #使用空格点号
git add --all

(2) Upload folder

  • git add folder
git add 文件夹名字   #文件夹下所有文件上传

--------------------------------------No text below---------- --------------------------------------------------

Note: For study only, record questions and reference, encourage each other!

Reference article:

1. git add command for multiple files or multiple folders_weixin_43688734's blog-CSDN blog_git command to add all files

 2.  Summary of git common commands

Guess you like

Origin blog.csdn.net/qq_39715000/article/details/126197190