Git常用操作
版本号相关
常看提交版本记录
1git log
回滚版本
1git reset --hard 版本号
查看所有的版本号(包括被回滚的)
1git relog 查看所有版本
查看git当前用户信息
提交github的时候显示的不是登录github的用户名,而是本地的git用户名
1查看当前git用户名: git config user.name
2查看当前git邮箱: git config user.email
3切换git用户名: git config --global user.name "YOURUSERNAME"
4切换git邮箱: git config --global user.email "YOUREMAIL"
将本地项目关联到远程
1git init
2git add .
3git commit -m '初始化项目'
4git remote add origin https://github.com/xienb/NPC.git
5git push -u origin master
.gitignore中删除已经被git add 的文件
使用场景:当项目中的一些不想被版本控制的文件被git add的时候,如果此时在gitignore文件中添加那些文件,此时是不起作用的,需要将add的文件重cache中删除,使用一下命令:
1$ git rm -r --cached .idea/
2error: the following file has staged content different from both the
3file and the HEAD:
4 .idea/workspace.xml
5(use -f to force removal)
6# 提示用-f进行删除
7
8# 继续输入一下命令可以删除
9$ git rm -rf --cached .idea/
10rm '.idea/compiler.xml'
11rm '.idea/description.html'
12rm '.idea/encodings.xml'
13rm '.idea/inspectionProfiles/Project_Default.xml'
14rm '.idea/misc.xml'
15rm '.idea/modules.xml'
16rm '.idea/uiDesigner.xml'
17rm '.idea/vcs.xml'
18rm '.idea/workspace.xml'
删除之后再用git status命令去看cache中的文件的时候,已经没有.idea中的内容
git修改已提交的记录中的用户名
- 先找到提交的记录 【5】 代表最近的五次提交记录
1$ git rebase -i HEAD~5
2pick 95320cb3 增加limit条数限制,优化sql
3pick e848c547 增加动态控制日志级别的 增加日志入为异常的时候保存丢失的数据
4pick 5664ee84 增加异常处理,当对象null时跳过。
5edit 468722a5 1.批量上下架判断子集情况 2.下发修改
6pick 4fb37a5f 修改
7
8# Rebase ed5437ed..4fb37a5f onto ed5437ed (5 commands)
9#
10# Commands:
11# p, pick = use commit
12# r, reword = use commit, but edit the commit message
13# e, edit = use commit, but stop for amending
14# s, squash = use commit, but meld into previous commit
15# f, fixup = like "squash", but discard this commit's log message
16# x, exec = run command (the rest of the line) using shell
17# d, drop = remove commit
18#
19# These lines can be re-ordered; they are executed from top to bottom.
20#
21# If you remove a line here THAT COMMIT WILL BE LOST.
22#
23# However, if you remove everything, the rebase will be aborted.
- 将想要改变信息的记录由pick->edit
- wq保存 提示信息如下
1Stopped at 72a09870... 1.批量上下架判断子集情况 2.下发修改
2You can amend the commit now, with
3
4 git commit --amend
5
6Once you are satisfied with your changes, run
7
8 git rebase --continue
- 执行
git commit --amend --author="作者 <邮箱@xxxx.com>" --no-edit命令
1$ git commit --amend --author="test <xxx@163.com>" --no-edit
2[detached HEAD 468722a5] 1.批量上下架判断子集情况 2.下发修改
3 Author: test <xxx@163.com>
4 Date: Tue Dec 31 10:08:26 2019 +0800
5 9 files changed, 91 insertions(+), 18 deletions(-)
- 执行
git rebase --continue
1$ git rebase --continue
2Successfully rebased and updated refs/heads/xxx.
- 执行
git push -f
1$ git push --force
git bash配合v2ray使用
1# 查看git代理配置
2git config --global http.proxy http://127.0.0.1:10809
3
4# 取消代理设置
5git config --global --unset http.proxy
6
7# 全局设置 http 代理此命令修改的文件为 C:\Users\用户名\.gitconfig (Windows 环境下)
单个项目独立配置
位于本地仓库文件的的.git文件夹的config文件中,需要显示所有文件
1[core]
2 repositoryformatversion = 0
3 filemode = false
4 bare = false
5 logallrefupdates = true
6 symlinks = false
7 ignorecase = true
8[remote "origin"]
9 url = https://github.com/xxx/spring-sourcecode-4.3.22.git
10 fetch = +refs/heads/*:refs/remotes/origin/*
11[user]
12 name = xxx
13 email = xxx@xx.xxx
14[branch "master"]
15 remote = origin
16 merge = refs/heads/master
— END —
相关标签