由于最近开始在新的公司上班了,终于告别了技术咨询的工作…感觉半年智商真的掉了不少,能够回来做开发/Research真的开心,上班的时候都在傻笑,感觉对面的小伙成天看智障的一样看着我…
废话不多说了,先上个阅读链接。
中文版Pro Git
https://git-scm.com/book/zh/v2
zh改成en就是英文版啦
这篇博文主要是我在阅读这份Pro Git的时候在最关键的地方做下的笔记
1 Git的三种状态
Git 的三种状态:
- committed:数据已经安全的保存在本地数据库中
- modified:修改了文件,但还没保存到数据库中
- staged:对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中
Git 项目的三个工作区域:
- .git directory(Repository):Git 用来保存项目的元数据和对象数据库的地方。 这是 Git 中最重要的部分,从其它计算机克隆仓库时,拷贝的就是这里的数据
- Working Directory:对项目的某个版本独立提取出来的内容。 这些从 Git 仓库的压缩数据库中提取出来的文件,放在磁盘上供你使用或修改
- Staging Area:一个文件,保存了下次将提交的文件列表信息,一般在 Git 仓库目录中。 有时候也被称作`‘索引’’,不过一般说法还是叫暂存区域
基本的 Git 工作流程如下:
- 在工作目录中修改文件
- 暂存文件,将文件的快照放入暂存区域
- 提交更新,找到暂存区域的文件,将快照永久性存储到 Git 仓库目录
2. Git reset
Hard reset of a single file:
git checkout HEAD -- my-file.txt
… which will update both the working copy of my-file.txt and its state in the index with that from HEAD.
– basically means: treat every argument after this point as a file name. More details in this answer. Thanks to VonC for pointing this out.
Reference for this part: hard reset of a single file
3. Git remove branch
To remove a local branch from your machine:
git branch -d {the_local_branch}
# use -D instead to force deleting the branch without checking merged status
To remove a remote branch from the server:
git push origin --delete {the_remote_branch}
4. Git clean
First about two states of files in working directory:
tracked
: Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. In short, tracked files are files that Git knows about.untracked
: Untracked files are everything else — any files in your working directory that were not in your last snapshot and are not in your staging area.
git reset --hard
和git clean -f
是一对好基友,结合使用他们能让你的工作目录完全回退到最近一次commit的时候。
More details about git clean
: https://git-scm.com/docs/git-clean