分支
删除分支
git branch --d tdapw-6.6
删除远程分支
git push origin --delete branch
创建新分支
默认从当前分支创建
git checkout -b tdapw-6.6
切换分支
git checkout qe-6.6
删除临时文件
直接删除的命令
# 删除 untracked files
git clean -f
# 连 untracked 的目录也一起删掉
git clean -fd
# 连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)
git clean -xfd
加上 -n 参数会查看将要删掉的文件,不会删除
git clean -nxfd
git clean -nf
git clean -nfd
删除git历史
git checkout --orphan newBranch
git add -A
git commit -am "message"
git branch -D master
#重命名当前分支:
git branch -m master
#强制提交:
git push -f origin master
撤销上次本地commit
git reset --soft HEAD^
示例
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git add .
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git commit -m "manypw to manytdpw"
[TDAPW-6.6 3175947] manypw to manytdpw
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100644 TDAPW6.6.tar.gz
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ ls
bin change.txt Developer Example LICENSE Makefile README.md src TDAPW6.6.tar.gz Tools
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git reset --soft HEAD^
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git status
On branch TDAPW-6.6
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: TDAPW6.6.tar.gz
modified: src/tdpw.f90
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ vi .gitignore
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ rm TDAPW6.6.tar.gz
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git add .
(python37) cndaqiang@mommint:~/code/TDAPW-6.6$ git commit -m "manypw to manytdpw"
[TDAPW-6.6 e51c21d] manypw to manytdpw
1 file changed, 5 insertions(+), 1 deletion(-)
撤销工作区对某文件的更改
git checkout ./Src/compinfo.F90(这是要撤销的文件名)
无法提交文件夹
因为文件夹下面是一个仓库,删除.git可以提交
(python37) [SSLAB chendq@login3 example-rpmd-c4]$git commit -m "all"
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: TDPW6.4-NVE-36-150K-Ey (modified content)
# modified: TDPW6.6-NVE-36-150K-Ey (modified content)
因为文件夹下面为空的
查看修改
查看改动的文件
git status
查看改动的细节
git diff 文件名
设置git config
默认编辑器
git config --global core.editor vim
修改单个仓库的.git/config
文件,在core中添加editor=vim
也行
本文首发于我的博客@cndaqiang.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!