Git Commands

当然,首先要先安装Git

安装命令:sudo apt-get install git

我在github上有个仓库,https://github.com/sunjieee/Homepage,那我们把它git到本地。

通过命令:git clone

如上图:远程仓库已经被clone到本地的~/Homepage中

这里我用的是ssh,当然也可以通过https,而https是需要输入用户名、密码,不太方便,但ssh第一次需要设置一下ssh key

设置可以按官方教程来,网址:https://help.github.com/articles/generating-ssh-keys/,在这里就不介绍了。

既然我们已经在本地有clone的仓库,那我们想往里面添加文件该怎么做呢?

首先,我们把要添加的文件放到该仓库目录下,在这里是~/Homepage中,

如图仓库中现在多了一个名叫SunJie.txt的文件,

当然也可以是本来在仓库里的文件,进行了编辑后,进行更新,比如更改README.md的内容后保存。

虽然我们已经把文件更新后放到仓库中,当其实这个文件只是在工作区。

可以通过命令:git status 查看

如上图,接下来我们要做的是使用命令: git add

如上图,我们git add后并没有显示说明,但其实我们已经把文件从工作区提交到暂存区了。

同样可以通过命令:git status 查看

接下来,我们需要把暂存区中的文件,一起提交给当前分支,这里是master分支,

注意这里时把暂存区的所有文件一次性提交,所以没必要每次git add 后都提交,

我们使用命令:git commit

如图进入了这个界面,可以输入一些信息记录这次commit。如:just for test。

提交好后,查看git status

1次提交,当前没有内容要提交

接下来,我们需要把本地仓库push到远程仓库,因为文件只在本地更新了。

使用命令:git push

再次,查看git status

可以看到已经完成了整个提交。

我们可以查看日志:git log

还有命令:git pull

以后每次工作前,把远程仓库git pull 到本地仓库,因为可以有其他人提交过更改。

还有 git checkout --file 命令

可以回到git commit/add 之前。

分支有master,dev,bug,feature,有不同用途。

其他命令以后再介绍。

最后附上工作区,暂存区,本地仓库和远程仓库的关系和执行命令后的变化。

时间: 2024-10-16 17:41:37

Git Commands的相关文章

MichaelBoselowitz/pygit2-examples: Examples of some "porcelain" git commands implemented with python bindings (pygit2) to the libgit2 library.

MichaelBoselowitz/pygit2-examples: Examples of some "porcelain" git commands implemented with python bindings (pygit2) to the libgit2 library.

[label][git-commands] Several Git Commands

The process of Git commands Operation 1. git commit -m 'fist post' Windows PowerShellCopyright (C) 2009 Microsoft Corporation. All rights reserved. C:\Users\james> cd f:/F:\> cd kamakawiwoF:\kamakawiwo> dirF:\kamakawiwo> git initInitialized em

Git - The most common git commands in the day-to-day work

We use git commands in the day to day work, below are the most common git commands I could think of. Create a new branch git branch <branchName> Switch to the new branch git checkout <branchName> Create a new branch and switch to it git checko

Git Commands Notes

Push Push changes to remote. (If the remote doesn't have the branch, the branch will be created) git push <remote name> <branch name> Renaming a branch (a complete version of push command) This can delete a  remote branch by providing empty lo

Useful Git Commands for me

查看Git追踪的文件 git ls-files 移除远程仓库的文件夹 git rm -r --cached some-directory git commit -m "Remove the now ignored directory some-directory" git push origin master 更新gitignore文件 git rm -r --cached . git add -A git commit -m "update .gitignore"

Very Good Article on How Git Commands Work

http://stackoverflow.com/questions/30038999/differences-between-commit-commit-and-push-commit-and-sync

关于git的一些使用

1.不懂就输入  git --help These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on

git manual

git(1) p,li,dt,dd,div,pre,h1,h2,h3,h4,h5,h6 { } body { margin: 1em 5% 1em 5% } a { color: blue; text-decoration: underline } a:visited { color: fuchsia } em { font-style: italic; color: navy } strong { font-weight: bold; color: #083194 } tt { color:

git workflows

https://www.atlassian.com/git/tutorials/comparing-workflows Comparing Workflows The array of possible workflows can make it hard to know where to begin when implementing Git in the workplace. This page provides a starting point by surveying the most