git撤销添加_如何撤消Git添加

git撤销添加

To undo git add before a commit:

要撤消git add在提交之前git add

Run git reset <file> or git reset to unstage all changes.

运行git reset <file>git reset以取消所有更改。

In older versions of git, the commands were git reset HEAD <file> and git reset HEAD respectively. This was changed in Git 1.8.2

在旧版本的git中,命令分别是git reset HEAD <file>git reset HEAD 。 在Git 1.8.2中进行了更改

You can read more about other commonly used Git actions in these helpful articles:

您可以在这些有用的文章中了解有关其他常用Git操作的更多信息:

Git checkout

Git结帐

Git pull vs Git fetch

Git Pull vs Git获取

Gitignore

吉特尼奥雷

这是有关Git的更多背景信息 (Here's a bit more background information about Git)

了解Git项目的三个部分 (Understand the Three Sections of a Git Project)

A Git project will have the following three main sections:

Git项目将包含以下三个主要部分:

  1. Git directory

    Git目录
  2. Working directory (or working tree)

    工作目录(或工作树)
  3. Staging area

    暂存区

The Git directory (located in YOUR-PROJECT-PATH/.git/) is where Git stores everything it needs to accurately track the project. This includes metadata and an object database which includes compressed versions of the project files.

Git目录 (位于YOUR-PROJECT-PATH/.git/ )是Git存储准确跟踪项目所需的所有内容的位置。 这包括元数据和一个对象数据库,其中包含项目文件的压缩版本。

The working directory is where a user makes local changes to a project. The working directory pulls the project’s files from the Git directory’s object database and places them on the user’s local machine.

用户在工作目录中对项目进行本地更改。 工作目录从Git目录的对象数据库中提取项目的文件,并将其放置在用户的本地计算机上。

The staging area is a file (also called the “index”, “stage”, or “cache”) that stores information about what will go into your next commit. A commit is when you tell Git to save these staged changes. Git takes a snapshot of the files as they are and permanently stores that snapshot in the Git directory.

暂存区域是一个文件(也称为“索引”,“阶段”或“缓存”),用于存储有关下一次提交内容的信息。 提交是指您告诉Git保存这些阶段的更改。 Git照原样拍摄文件快照,并将该快照永久存储在Git目录中。

With three sections, there are three main states that a file can be in at any given time: committed, modified, or staged. You modify a file any time you make changes to it in your working directory. Next, it’s staged when you move it to the staging area. Finally, it’s committed after a commit.

在三个部分中,文件可以在任何给定时间处于三种主要状态:提交,修改或暂存。 您修改一个文件您在您的工作目录更改它的任何时间。 其次,这是当你将它移动到临时区域上演 。 最后,在提交之后提交。

安装Git (Install Git)

配置Git环境 (Configure the Git Environment)

Git has a git config tool that allows you to customize your Git environment. You can change the way Git looks and functions by setting certain configuration variables. Run these commands from a command line interface on your machine (Terminal in Mac, Command Prompt or Powershell in Windows).

Git有一个git config工具,可让您自定义Git环境。 您可以通过设置某些配置变量来更改Git的外观和功能。 从计算机上的命令行界面(在Mac中为终端,在Windows中为Command Prompt或Powershell)运行这些命令。

There are three levels of where these configuration variables are stored:

这些配置变量的存储级别分为三个级别:

  1. System: located in /etc/gitconfig, applies default settings to every user of the computer. To make changes to this file, use the --system option with the git config command.

    系统:位于/etc/gitconfig ,将默认设置应用于计算机的每个用户。 要对此文件进行更改,请在git config命令中使用--system选项。

  2. User: located in ~/.gitconfig or ~/.config/git/config, applies settings to a single user. To make changes to this file, use the --global option with the git config command.

    用户:位于~/.gitconfig~/.config/git/config ,将设置应用于单个用户。 要对此文件进行更改,请在git config命令中使用--global选项。

  3. Project: located in YOUR-PROJECT-PATH/.git/config, applies settings to the project only. To make changes to this file, use the git config command.

    项目:位于YOUR-PROJECT-PATH/.git/config ,仅将设置应用于项目。 要对此文件进行更改,请使用git config命令。

If there are settings that conflict with each other, the project-level configurations will override the user-level ones, and the user-level configurations will override the system-level ones.

如果存在彼此冲突的设置,则项目级别的配置将覆盖用户级别的配置,而用户级别的配置将覆盖系统级别的配置。

Note for Windows users: Git looks for the user-level configuration file (.gitconfig) in your $HOME directory (C:\Users\$USER). Git also looks for /etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer. If you are using version 2.x or later of Git for Windows, there is also a system-level config file at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer. This config file can only be changed by git config -f FILE as an admin.

Windows用户注意事项:Git在$HOME目录( C:\Users\$USER )中查找用户级别的配置文件( .gitconfig )。 Git还会查找/etc/gitconfig ,尽管它是相对于MSys根目录的,但在运行安装程序时,无论您决定在Windows系统上安装Git,它都是该根目录。 如果您使用的是Windows 2.x或更高版本的Git,则在Windows XP上的C:\Documents and Settings\All Users\Application Data\Git\config以及C:\ProgramData\Git\config也有一个系统级的配置文件C:\ProgramData\Git\config Windows Vista及更高版本上的C:\ProgramData\Git\config 。 此配置文件只能由git config -f FILE更改为管理员。

添加您的姓名和电子邮件 (Add Your Name and Email)

Git includes the user name and email as part of the information in a commit. You’ll want to set this up under your user-level configuration file with these commands:

Git在提交中将用户名和电子邮件作为信息的一部分。 您需要使用以下命令在用户级配置文件下进行设置:

git config --global user.name "My Name"
git config --global user.email "myemail@example.com"

更改文字编辑器 (Change Your Text Editor)

Git automatically uses your default text editor, but you can change this. Here’s an example to use the Atom editor instead (the --wait option tells the shell to wait for the text editor so you can do your work in it before the program moves on):

Git自动使用您的默认文本编辑器,但是您可以更改它。 这是一个改用Atom编辑器的示例( --wait选项告诉Shell等待文本编辑器,以便您可以在程序继续之前在其中进行工作):

git config --global core.editor "atom --wait"

为Git输出添加颜色 (Add Color to Git Output)

You can configure your shell to add color to Git output with this command:

您可以使用以下命令将外壳配置为向Git输出添加颜色:

git config --global color.ui true

To see all your configuration settings, use the command git config --list.

要查看所有配置设置,请使用命令git config --list

在项目中初始化Git (Initialize Git in a Project)

Once Git is installed and configured on your computer, you need to initialize it in your project to start using its version control powers. In the command line, use the cd command to navigate to the top-level (or root) folder for your project. Next, run the command git init. This installs a Git directory folder with all the files and objects Git needs to track your project.

一旦在计算机上安装并配置了Git,就需要在项目中对其进行初始化,以开始使用其版本控制功能。 在命令行中,使用cd命令导航到项目的顶级(或根)文件夹。 接下来,运行命令git init 。 这将安装一个Git目录文件夹,其中包含Git跟踪项目所需的所有文件和对象。

It’s important that the Git directory is installed in the project root folder. Git can track files in subfolders, but it won’t track files located in a parent folder relative to the Git directory.

将Git目录安装在项目根文件夹中非常重要。 Git可以跟踪子文件夹中的文件,但不会跟踪相对于Git目录的父文件夹中的文件。

在Git中获得帮助 (Get Help in Git)

If you forget how any command works in Git, you can access Git help from the command line several ways:

如果您忘记了任何命令在Git中的工作方式,则可以通过几种方式从命令行访问Git帮助:

git help COMMAND
git COMMAND --help
man git-COMMAND

This displays the manual page for the command in your shell window. To navigate, scroll with the up and down arrow keys or use the following keyboard shortcuts:

这将在您的shell窗口中显示该命令的手册页。 要进行导航,请使用向上和向下箭头键滚动或使用以下键盘快捷键:

  • f or spacebar to page forward

    f或空格键可向前翻页
  • b to page back

    b返回页面
  • q to quit

    q退出

翻译自: https://www.freecodecamp.org/news/how-to-undo-a-git-add/

git撤销添加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值