Visual Studio Code configures git and common git commands for code management

If you pay attention to the changes in the project code of a github or gitlab project for a long time, or if you need to update, upload or pull the code, it is very inconvenient to git the entire project code every time. Combined with git commands, you can directly pull part of the uploaded or updated code, which is very convenient and simple.

I use the vscode code editor. I often need to read the code and modify the debugging code in my daily life. The project framework is often updated, and I need to pull it out in time to learn and apply it. Since my vscode configuration git failed before, every time I updated the code, I opened the Git Bash interface and copied ssh or http to git clone. Over time, I pulled many versions of the code of a framework, and different versions had their own There are also changes, so after pulling the new version, you can't delete the old one, so there are a lot of them accumulated, and it's not easy to find the code you want to use, which is very annoying.

1. Configure git in vscode

Insert image description here

Insert image description here

I have been using it too frequently recently, and I need to update it in a day or two, so I completely uninstalled the previous software, reinstalled and set it up, and it worked. I was very happy. Take note of this for now, as you will need to repeat the work later for easy reference.

The first is to install vscode: https://code.visualstudio.com/DownloadDownload
git: https://registry.npmmirror.com/binary.html?path=git-for-windows/
Regarding the installation process, I have both software It is installed with default settings

The next step is to set vscode to use git in the terminal. In fact, just configure the startup file:
open vscode, click File - Preferences - Settings,
Insert image description here
search for terminal.intergrated.shell.windows after opening, click Edit and open, and then Add the path to the installed git bash.exe, as shown below:

Insert image description here
Insert image description here
Insert image description here
After adding the path, save it. Then click the shortcut key ctrl + ~, which will directly open the git terminal interface: you
Insert image description here
can use git commands at this time.

Regarding tutorials on configuring ssh in gitlab or github, I have done it a long time ago and I don’t need to do it again. I will post a few tutorials:
vscode + git configuration: https://www.cnblogs.com/liangxuran/p/ 13715482.html
git settings user: https://zhuanlan.zhihu.com/p/183200664
git configuration

2. Common commands for git management code

Refer to the Zhihu blog: https://zhuanlan.zhihu.com/p/135183491
Insert image description here
Generally speaking, the code will be cloned to the local warehouse first, and the code will be modified and upgraded based on the workspace in the local warehouse. The modified code will be added from the workspace. Go to the staging area index, which can be edited at this time. Submitting the code from the staging area to the local warehouse will form a version, and the modifications will always exist. The code submitted to the local warehouse can be push-uploaded to the remote warehouse remotely. At this time, everyone can see your modified code. If others in the remote repository have updates, in order to keep the local repository synchronized, the updates can be pulled to the local repository through pull. Some commands involved:

"""设置用户,相当于注册一个用户"""
git config --global user.name "xxx"
git config --global user.email "[email protected]"

""" 通过命令 git init 把这个目录变成git可以管理的仓库"""
git init

"""把修改或新建的文件代码添加到暂存区index"""
git add xxx.py

"""把修改或新建的文件代码从暂存区index添加到本地仓库"""
git commit -m "修改说明" xxx.py

(注:不加py文件可一次性把所有更新提交)

"""可以通过命令git status来查看是否还有文件未提交"""
git status
 """想查看下历史记录,近期或全部记录"""
 git reflog
 git log

"""git checkout -- file 可以丢弃工作区的修改,具体见后说明"""
git checkout --file 

"""把本地库的内容推送到远程,使用 git push命令,把当前分支xxx推送到远程"""
git push origin xxx

"""从远程库克隆到本地库"""
git clone https:xxxx(具体查询实际网址)

"""创建分支xxx"""
git branch xxx

"""切换分支到xxx1"""
git checkout xxx1

"""可以把xxx分支上的内容合并到分支master上,在master分支上,使用如下命令  """
git checkout master
git merge xxx

"""删除分支xxx"""
git branch –d xxx

Insert image description here

"""关于文件状态"""

untrack表示是新文件,没有被add过,是为跟踪的意思。

not staged 表示add过的文件,即跟踪文件,再次修改没有add,就是没有暂存的意思

Changes not staged for commit,说明已跟踪文件的内容发生了变化,但还没有放到暂存区。
要暂存这次更新,需要运行 git add 命令

Insert image description here

"""删除本地仓库文件并更新到远程的个人分支"""
git rm xxx
git commit -m "rm xxx"
git push origin person_xxx

Remote personal branch and master branch

"""1、个人分支xxx更新"""
git add file
git commit -m "add file " file
git push origin xxx

"""2、切换至主分支master合并个人分支xxx"""
git checkout master
git merge xxx


"""在个人分支拉取主分支代码"""
git checkout xxx
git pull origin master

"""master主分支代码更新上传至仓库"""
git add .
git commit -m "update"
git push

Guess you like

Origin blog.csdn.net/qq_44442727/article/details/125843638