为什么需要下载Git,如果它已内置于VS Code中?

huangapple go评论121阅读模式
英文:

Why do I need to download Git, if it is built into VS Code?

问题

我注意到在我的笔记本电脑上,它允许我初始化仓库并在Visual Studio Code中使用源代码控制。但是当我在我的主要台式电脑上打开源代码控制时,它告诉我要下载Windows版的Git。

在我的笔记本电脑上,我从未下载过Git,但现在在我的台式电脑上必须下载。

有人之前遇到过这个问题吗?

所以我按照它说的下载了Git,然后它告诉我可以重新打开已关闭的仓库。

在下载Git之前:

在下载Git之后:

如果我点击重新打开仓库:

那个仓库甚至都不会打开。

英文:

I have noticed that on my laptop, it lets me initialize repositories and use source control in visual studio code. But when I go to source control on my main PC, it tells me to download git for windows.

为什么需要下载Git,如果它已内置于VS Code中?

On my laptop I have never downloaded git but now on my pc I have to.

为什么需要下载Git,如果它已内置于VS Code中?

Has anyone had this issue before?

So I downloaded git as it said and it tells me that I can reopen closed repository. So I downloaded git as it said and it tells me that I can reopen closed repository.

before downloading git:

为什么需要下载Git,如果它已内置于VS Code中?

after downloading git:

为什么需要下载Git,如果它已内置于VS Code中?

if i press reopen repository:

为什么需要下载Git,如果它已内置于VS Code中?

That repository doesn't even open.

答案1

得分: 2

为什么我需要下载 Git,如果它已经内置在 VS Code 中?

据我所知,Git 并没有内置在 VS Code 中。

实际上,官方文档中在 https://code.visualstudio.com/docs/sourcecontrol/overview#_working-in-a-git-repository 上写着:

确保安装了 Git。 VS Code 将使用您机器上的 Git 安装(至少版本为 2.0.0),因此您需要在使用这些功能之前安装 Git

如果在您的某台机器上能够使用 VS Code 的 Git 支持,这意味着在您获取它之前已经安装了 Git,或者在您拥有它的某个时刻已经安装了 Git。

对于 macOS,请参考 Is git pre-installed on macOS Sierra?Is git already installed when buying a new Macbook?。简而言之,它附带了一个提示您实际安装 Git 的外壳。

英文:

> Why do I need to download Git, if it is built into VS Code?

As far as I know, Git is not built into VS Code.

Indeed, from the official docs at https://code.visualstudio.com/docs/sourcecontrol/overview#_working-in-a-git-repository:

> Make sure Git is installed. VS Code will use your machine's Git installation (at least version 2.0.0), so you need to install Git first before you get these features.

If on one of your machines you were able to use the Git support of VS Code, that means Git was already installed before you got it, or that sometime when you had it, it was installed.

For macOS, see Is git pre-installed on macOS Sierra? and Is git already installed when buying a new Macbook?. TL;DR it comes with a shim that prompts you to actually install Git.

答案2

得分: 0

很可能是您的VS Code安装默认安装了它。通常情况下,如果您使用VS Code,您需要在计算机上安装Git客户端并启用它

额外细节

如果您对Git的概念不熟悉,可以继续阅读以更好地理解整体情况。

Git分布式版本控制系统,允许开发人员在软件开发过程中跟踪源代码变化。它速度快且非常灵活。您可以创建任意数量的分支并随意切换分支。

分布式版本控制系统意味着Git具有存储在服务器上的远程仓库和存储在每个开发人员计算机上的本地仓库。这意味着代码不仅存储在中央服务器上,而且完整的代码副本存在于所有开发人员的计算机上(假设他们都将最新代码拉到了自己的计算机上)。

要使用Git仓库,您应该安装Git客户端

Git客户端是一种允许您与Git仓库互动的软件应用程序。您可以使用Git客户端执行诸如提交更改、创建分支、合并更改等操作。一些流行的Git客户端包括Git CLI、GitKraken和SourceTree。许多开发人员喜欢使用类似于Git Bash、Windows上的命令提示符或PowerShell以及macOS上的Homebrew、MacPorts、Xcode等应用程序进行工作。

奖励

许多人更喜欢使用Git GUI客户端,这是命令行选项(如Git Bash)的强大替代品。我个人建议您逐渐习惯使用命令行工具。以下是最常见的bash命令。

为用户信息设置全局设置

$ git config --global user.name "[姓名]"

$ git config --global user.email "[电子邮件地址]"

检查状态

git status

克隆项目并处理分支

$ git clone [存储库链接]

$ git checkout [分支名称]

创建新分支

$ git checkout -b feature/[分支名称]

$ git checkout -b bugfix/[分支名称]

$ git checkout -b release/[分支名称]

重命名现有分支

从bugfix到feature的长版本(示例中)

git branch -m bugfix/[分支名称] feature/[分支名称]

从bugfix到feature的短版本(示例中)

git branch -m {bugfix,feature}/[分支名称]

添加更改以进行提交

这是为单个文件添加更改,以下两个命令是添加所有允许的更改文件

$ git add [文件]

$ git add -A

$ git add .

提交和推送

$ git commit -m "提交消息"
$ git push

如果分支是新创建的。

$ git push --set-upstream [远程] [分支名称]

更改最近的提交消息

$ git commit --amend -m "新的提交消息"

拉取、获取和合并

$ git pull

$ git fetch

$ git merge [分支名称]

重置更改

$ git reset [提交]

$ git reset --hard [最后已知的良好提交]

取消上一次提交,不保留更改。

$ git reset --hard HEAD~1

取消上一次提交,保留更改。

$ git reset --soft HEAD~1

显示所有被忽略的文件

$ git status --ignored

检查本地、远程和所有分支

$ git branch

$ git branch -r

$ git branch -a

删除本地分支

$ git branch -d feature/branch-name

$ git branch -d bugfix/branch-name

$ git branch -d hotfix/branch-name

删除远程分支

$ git push origin --delete feature/branch-name

标签检查和创建

$ git tag

$ git tag -a [标签名称] -m "标签描述"

$ git push origin [标签名称]

在我当前使用HTTPS的仓库中开始使用SSH

$ git remote set-url origin git@ssh.dev.azure.com:v3/rest-of-your-project-ssh-url

存储更改

将未提交的更改保存在“stash”中。这将从工作树中删除更改。

$ git stash

列出stash

$ git stash list

将stash应用到当前分支的工作树中

$ git stash apply

应用stash 0 - 更改数字以应用其他stash

$ git stash apply stash@{0}

从stash列表中删除stash 0 - 更改数字以应用其他stash。

$ git stash drop stash@{0}

应用所选的stash并从stash列表中删除它。

$ git stash pop stash@{1}

显示当前分支的所有提交以及父分支和其提交

$ git log --first-parent

退出git日志历史

退出

$ :q

获取帮助

$ :h
英文:

It is likely that your VS Code installation installed it by default. Normally you need to install a Git Client on your computer and enable it for VS Code if you are using it.

Additional details

Please continue to read if you are new to the concept of Git to understand the big picture better.

Git is a distributed version control system that lets developers track source code changes during software development. It is fast and super flexible. You can create as many branches as you need and switch between branches as you wish.

Distributed Version Control System means Git has a remote repository which is stored on a server and a local repository which is stored on the computer of each developer. This means the code is not just stored on a central server, but the full copy of the code is present on all developers' computers (assuming they all pulled the latest code to their computers).

In order to work with a Git repo, you should install a Git Client.

A Git client is a software application that allows you to interact with a Git repository. You can use a Git client to perform actions such as committing changes, creating branches, merging changes, and more. Some popular Git clients include Git CLI, GitKraken, and SourceTree. A lot of developers prefer to work with applications like Git Bash, Command Prompt or PowerShell on Windows and Homebrew, MacPorts, Xcode on macOS.

Bonus

Quite a few people prefer to work with a Git GUI client which is a powerful alternative to command line options like Git Bash. I personally recommend you to get used to working with a command line tool. Below are the most common bash commands.

Set global settings for user information

$ git config --global user.name "[name]"

$ git config --global user.email "[email address]"

Check status

git status

Clone a project and working with branches

$ git clone [https://repository-link]

$ git checkout [branch-name]

Creating a new branch

$ git checkout -b feature/[branch-name]

$ git checkout -b bugfix/[branch-name]

$ git checkout -b release/[branch-name]

Renaming an existing branch

Long version of renaming a branch (from bugfix to feature in this example)

git branch -m bugfix/[branch-name] feature/[branch-name]

Short version of renaming a branch (from bugfix to feature in this example)

git branch -m {bugfix,feature}/[branch-name]

Adding changes for commit

This is for adding a single file, following 2 commands are adding all allowed changed files

$ git add 

$ git add -A

$ git add .

Committing and pushing

$ git commit -m "commit message"
$ git push

If the branch is newly created.

$ git push --set-upstream [remote] [branch-name]

Changing the most recent commit message

$ git commit --amend -m "new commit message"

Pull, fetch and merge

$ git pull

$ git fetch

$ git merge [branch-name]

Reset changes

$ git reset [commit]

$ git reset --hard [last-known-good-commit]

Undo the last commit, do not keep the changes.

$ git reset --hard HEAD~1 

Undo the last commit, keep the changes.

$ git reset --soft HEAD~1

Show all ignored files

$ git status --ignored

Check local, remote and all branches

$ git branch

$ git branch -r

$ git branch -a

Delete a local branch

$ git branch -d feature/branch-name

$ git branch -d bugfix/branch-name

$ git branch -d hotfix/branch-name

Delete a remote branch

$ git push origin --delete feature/branch-name

Tag checking and creation

$ git tag

$ git tag -a [tag-name] -m "tag description"

$ git push origin [tag-name]

Start using SSH in a repository where I am currently using HTTPS

$ git remote set-url origin git@ssh.dev.azure.com:v3/rest-of-your-project-ssh-url

Stash changes

Save the un-committed changes in a "stash". This will remove changes from working tree.

$ git stash

List the stashes

$ git stash list

Apply stash to working tree in current branch

$ git stash apply

Apply the stash 0 - change the number in order to apply other stashes

$ git stash apply stash@{0}

Remove the stash 0 from stash list - change the number in order to apply other stashes.

$ git stash drop stash@{0}

Apply the selected stash and remove it from the stash list.

$ git stash pop stash@{1}

Show all commits of the current branch as well as the parent branch and its commits

$ git log --first-parent

Exit git log history

For exit

$ :q

For help

$ :h

huangapple
  • 本文由 发表于 2023年8月10日 17:09:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874248.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定