Git 使用总结

码上解忧铺2016-01-30 20:18:01笔记Git

笔记整理自网站 Try Gitopen in new window,一套很不错的 Git 在线入门教程。

git init

To initialize a Git repository here
要初始化 Git 存储库中

Directory

  • A folder used for storing multiple files.
    用于存储多个文件的文件夹。

Repository

  • A directory where Git has been initialized to start version controlling your files.
    Git 已初始化启动版本控制文件的目录。

git status

See what the current state of the project is.
请参阅该项目的当前状态是什么。

staged

  • Files are ready to be committed.
    文件是准备被提交。

unstaged

  • Files with changes that have not been prepared to be committed.
    包含已不准备提交的更改的文件。

untracked

  • Files aren't tracked by Git yet. This usually indicates a newly created file.
    然而 git 跟踪不是文件。这通常表明一个新创建的文件。

deleted

  • File has been deleted and is waiting to be removed from Git.
    文件已被删除,等待从 Git 中删除。

git add <file>

Add files to the staging area.
将文件添加到暂存区域。

Staging Area

  • A place where we can group files together before we "commit" them to Git.
    在那里我们可以将文件分组在一起之前我们"死记",Git 一个地方。
    Commit
    提交

add all

  • You can also type git add -A . where the dot stands for the current directory, so everything in and beneath it is added. The -A ensures even file deletions are included.
    您也可以键入 git add-A。其中点代表当前目录,因此,一切都在和它下面添加。'-A' 确保甚至删除文件都包括在内。

git reset

You can use git reset <filename> to remove a file or files from the staging area.
可以使用 git 复位 <filename>要删除的文件从临时区域。

Commit

A "commit" is a snapshot of our repository. This way if we ever need to look back at the changes we've made (or if someone else does), we will see a nice timeline of all changes.
"提交"是我们的存储库的快照。这种方式如果我们需要回头看变化我们已经取得了 (或如果别人做),我们将看到一个好时间线的所有更改。

git commit -m "msg"

  • To store our staged changes we run the commit command with a message describing what we've changed.
    来存储我们的阶段性的变化我们描述我们已经改变了的消息与运行提交命令。

'-a' option

  • Auto removes deleted files with the commit.
    自动删除已删除的文件一起提交。
git commit -am "msg"

git log

a journal that remembers all the changes we've committed so far
记得的所有更改的日志我们犯为止

git log --summary

  • see more information for each commit. You can see where new files were added for the first time or where files were deleted. It's a good overview of what's going on in the project.
    看到每次提交的详细信息。你可以看到第一次在哪里添加新的文件或删除文件的位置。它是在项目中怎么好概述。

git remote

git remote add <remote name> <repository URL>
git remote add origin https://github.com/try-git/try_git.git

Git doesn't care what you name your remotes, but it's typical to name your main one origin.
Git 并不在乎你的名字你的遥控器,但它是典型的名字你主要的一个原点。

It's also a good idea for your main repository to be on a remote server like GitHub in case your machine is lost at sea during a transatlantic boat cruise or crushed by three monkey statues during an earthquake.
它也是一个好主意你主要的存储库,要像 GitHub 万一你的机器是在一艘横渡大西洋的船迷失在大海航行的远程服务器上,或在地震中被压在三个猴子雕像。

git push

Tells Git where to put our commits when we're ready.
告诉 Git 在哪里,把我们提交时,我们准备好了。

git push -u <remote name> <branch name>
git push -u origin master

The -u tells Git to remember the parameters, so that next time we can simply run git push.
'-U' 告诉 Git 要记住参数,以便下一次我们可以简单地运行git push。

git stash

Sometimes when you go to pull you may have changes you don't want to commit just yet. One option you have, other than commiting, is to stash the changes.
有时当你去拉你可有改变你不想只是还没有提交。你除了提交,还有一个选择是藏所做的更改。

Use the command git stash to stash your changes, and git stash apply to re-apply your changes after your pull.
使用命令 'git 藏匿' 到藏您的更改,和 git 藏匿应用来重新应用您的更改后你的拉。

git pull

git push <remote name> <branch name>
git pull origin master

Check for changes on remote repository and pull down any new changes.
检查对远程资源库中的更改和拉下任何新的变化。

git diff

A good overview of changes we have made and lets us add files or directories one at a time and commit them separately.
很好地概述的变化我们取得,让我们一次添加文件或目录一并提交他们分开。

git diff HEAD

  • Show what is different from our last commit. HEAD points to your most recent commit by default.
    显示什么是从我们最后提交不同。默认情况下,' HEAD ' 指向您最新提交。

git diff --staged

  • Look at changes within files that have already been staged.
    看看已经发动的文档内的修改。

git checkout -- <target>

Changed files back to how they were at the last commit, namely get rid of all the changes since the last commit.
已更改的文件返回到他们是如何在最后的承诺,即摆脱所有更改自上次提交。

--: promise the command line that there are no more options after the '--', avoid switching to the branch of the same name.
'— — ': 保证命令行有没有更多的选择后,' — — ',避免切换到具有相同名称的分支。

git branch

List local branches of now repository.
列出现在资料库的地方分支机构。

git branch <name>

  • Create a new branch.
    创建一个新的分支。

When developers are working on a feature or bug they'll often create a copy (aka. branch) of their code they can make separate commits to. Then when they're done they can merge this branch back into their main master branch.

git checkout <branch>

  • Switch to certain branch.
    切换到某个分支。

git checkout -b new_branch

  • Checkout and create a branch at the same time.
    签出和在同一时间创建一个分支。

git rm <file>

Not only remove the actual files from disk, but will also stage the removal of the files for us.
不仅从磁盘,删除实际的文件也将阶段我们文件的删除。

git rm -r folder

  • Recursively remove all folders and files from the given directory.
    从给定的目录中递归删除所有文件夹和文件。

git merge <branch>

Merge your changes from the given branch into current branch.
将你给定的分支中的更改合并到当前分支。

Merge Conflicts

  • Merge Conflicts can occur when changes are made to a file at the same time. Reading more on
    在同一时间对文件进行更改时,可能会发生合并冲突。阅读更多关于
    how conflicts are presentedopen in new window.

Delete Branch

git branch -d <branch>

  • Delete a local branch. -d won't let you delete something that hasn't been merged.
    删除本地分支。'-d' 不会让你删除尚未合并的东西。

-f and -D

  • Force delete the branch that hasn't been merged.
    删除尚未合并的分支。

Add the -f(--force) option or use -D which combines -d -f together into one command.

Delete Remote Branch

git branch -r -d <remote name>/<branch name>
git push <remote name>: <branch name>
git branch -r -d origin/branch-name
git push origin :branch-name
Last Updated 8/3/2024, 10:56:46 AM