1. How to make Git “forget” about a file that was tracked but is now in gitignore?

初始化是忘了添加.gitignore, 后边添加了,如何让git不在索引已经跟踪的文件?

在工程中很容易出现.gitignore并没有忽略掉我们已经添加的文件,那是因为.gitignore对已经追踪(track)的文件是无效的,需要清除缓存,清除缓存后文件将以未追踪的形式出现,这时重新添加(add)并提交(commit)就可以了。

git rm -r --cached .  //删除git的整个索引树
git add .    // 重建git索引
git commit -am "Remove ignored files"

git cherry -v, 查看未push commit

2. rebase & reset

git rebase

git reset --hard HEAD~1, 撤销最近一次commit,就像没有commit一样,上次的change会丢弃

git reset --soft HEAD~1, 撤销最近一次commit,但是上一次的change 还保留着

3.gitignore file

*.a                   # 忽略所有 .a 伟扩展名的文件
!lib.a                # 但是 lib.a 不忽略,即时之前设置了忽略所有的 .a
build/               # 忽略所有的 build/ 目录下文件
.vs/ #忽略vs2017的配置文件

4. git checkout

git checkout .  #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

5. git checkout commit-id

git checkout -b new_branch 6e559cb ,切换到一个指定提交点

6. git update-index

This will tell git you want to start ignoring the changes to the file
git update-index --assume-unchanged path/to/file

When you want to start keeping track again
git update-index --no-assume-unchanged path/to/file