关于git的使用笔记(Notes on Git)

拉取指定分支:git clone -b 分支名 远程仓库地址

git fetch
git switch -c new-branch orgin/master
git push origin new-branch

git stash push

git reset –hard
git clean -fd

git config –global user.name “马季12989”
git config –global user.email “12989@sangfor.com”
ssh-keygen -t rsa -C “12989@sangfor.com” -b 4096
cat ~/.ssh/id_rsa.pub

git push origin master:feature-libfreetype-upgrade-maji

查看当前的分支是基于哪个分支创建的
git reflog –date=local –all | grep
基于远端分支拉取本地分支
git checkout -b nta2.0.7-PHPOffice-Common-delet-maji origin/dev-nta2.0.7-sec
如果在修改时发现修改错误,而要放弃本地修改时
1.未使用 git add 缓存代码时。
可以使用 git checkout — filepathname (比如: git checkout — readme.md ,不要忘记中间的 “–” ,不写就成了检出分支了!!)。放弃所有的文件修改可以使用 git checkout . 命令。
2.已经使用了 git add 缓存了代码。
可以使用 git reset HEAD filepathname
3.已经用 git commit 提交了代码
切分支出现错误时
git fetch origin

git远程仓库版本回退方法:
1.基于需要回退的分支拉取,并更新
2.git log –oneline -6 查看提交日志,记录要回退版本的值”value”
3.备份本地分支、远程分支
4.git reset –hard value
5.查看提交日志git log –oneline 确定成功后进行下一步
6.删除远端仓库分支名(需要和原来仓库名字一致的情况)
7.建立本地分支,和远端分支名字一致
7.git push origin 远端分支名

git强制切分支:git checkout -f xxx
git 清除所有修改 git clean -f
删除本地已合并的分支:git branch -d [branchname]
本地放弃合并 git merge –abort
黑鸭扫描时git报错:set GIT_PYTHON_GIT_EXECUTABLE=C:\Program Files\Git\cmd\git.exe

git log –stat -1 提交包含信息
git stash 先保存到本地,后面再来处理
git stash pop 恢复位于栈顶的被储存修改
git stash list 检查储存了什么东西
git stash pop stash@{1} 恢复更早之前的修改
git log –follow filename 文件被重命名后的历史记录
git checkout –force branchname 强制切换分支
git stash 切分支出错,先储存
git branch branchname 散列值 恢复删除的分支
git reflog 分支切换的具体信息
git branch branchname HEAD@{1}
git gc 垃圾回收(garbage collect)
git remote prune origin 同步远程分支,删除本地多余分支
git reset –merge 取消合并
git pull –rebase
git fetch -p 清除已删除远程分支
git log –walk-reflogs branchname 分支的本地历史记录
git push origin :branchname 删除远端分支
git remote show origin 查看远程分支状态
git config –global core.editor “‘C:\Program Files (x86)\Notepad++\notepad++.exe’ -multiInst -notabbar -nosession -noPlugin ‘$*'” 配置commit编辑器功能
git log –oneline -30 合并commit

git在rebase的时候出现
error: The following untracked working tree files would be overwritten by merge:
.idea/workspace.xml
Please move or remove them before you merge.

使用命令:git clean -d -fx 删除 一些 没有 git add 的 文件;
git clean 参数

-n 显示将要删除的文件和目录;



-x -----删除忽略文件已经对git来说不识别的文件



-d -----删除未被添加到git的路径中的文件



-f -----强制运行

git cherry-pick id 挪动其他分支的提交信息到当前分支中

查询文件权限:
git ls-tree HEAD
git权限修改:
git update-index –chmod=+x filename

关联其他分支:
git branch –set-upstream-to=origin/分支名字

修改commit信息
git commit –amend

同步远程分支到本地
git fetch

回滚到指定提交
git reset 提交id

回滚到上一个提交
git reset –hard HEAD

合并提交信息
git rebase -i 提交id

缓存当前更改
git stash

查看当前缓存
git stash list

释放当前缓存到当前分支
git stash pop

git解决冲突

  • 切分支到版本主分支 git checkout dev-nta2.0.8 && git pull
  • git rebase dev-nta2.0.8 && 解决冲突(解决冲突时是一个一个文件解决的,意思是解决一个冲突文件就要执行一次第3 步)
    3 . 解决冲突文件 && git status && git add conflict_file && git rebase –continue
  • 重复上面第3步,直到解决所有冲突文件后
  • git push origin your_branch

git垃圾清理解决方法:
1.输入命令:git fsck –lost-found,可以看到好多“dangling commit”
2.清空他们:git gc –prune=now,完成

windows支持长路径,要不然代码路径太长会报错

git config –global core.longpaths true

windows默认下载git代码,没有显示链接link属性问题

git config –global core.symlinks true

windows下载代码编码格式,不会进行转换,提交不转换(默认安装会转换成windows)

git config –global core.autocrlf false

————————

Pull the specified branch: git clone – B branch name remote warehouse address

git fetch
git switch -c new-branch orgin/master
git push origin new-branch

git stash push

git reset –hard
git clean -fd

git config –global user.name “马季12989”
git config –global user.email “12989@sangfor.com”
ssh-keygen -t rsa -C “12989@sangfor.com” -b 4096
cat ~/.ssh/id_rsa.pub

git push origin master:feature-libfreetype-upgrade-maji

View which branch the current branch is created on
git reflog –date=local –all | grep
Pull local branch based on remote branch
git checkout -b nta2. 0.7-PHPOffice-Common-delet-maji origin/dev-nta2. 0.7-sec
If a modification error is found during modification and you want to discard the local modification
1. When git add cache code is not used.
You can use git checkout — filepathname (for example: git checkout — readme.md, don’t forget the “-” in the middle, and it will become the check-out branch if you don’t write it!!). To discard all file modifications, you can use git checkout Command.
2. Git add has been used to cache the code.
You can use git reset head filepathname
3. The code has been submitted with git commit
Error cutting branch
git fetch origin

Git remote warehouse version fallback method:
1. Pull and update based on the branch that needs to be fallback
2. Git log — oneline – 6 view the submission log and record the value “value” of the version to be fallback
3. Backup local branch and remote branch
4.git reset –hard value
5. Check the submission log git log — oneline and proceed to the next step after confirming success
6. Delete the branch name of the remote warehouse (if it needs to be consistent with the original warehouse name)
7. Establish a local branch with the same name as the remote branch
7. Git push origin remote branch name

Git forced branch cutting: git checkout – f XXX
Git clear all modifications git clean – F
Delete local merged branch: git branch – D [branchname]
Discard local merge git merge — abort
Git error during black duck scanning: set Git_ PYTHON_ GIT_ EXECUTABLE=C:\Program Files\Git\cmd\git. exe

Git log — stat – 1 submission contains information
Git stash is saved locally and processed later
Git stash pop restores stored modifications at the top of the stack
Git stash list check what is stored
Git stash pop stash@{1} reverts to earlier modifications
Git log — follow filename is the history of the renamed file
Git checkout — force branchname force branch switching
Git stash branch cutting error, save first
Git branch branchname hash value restores the deleted branch
Specific information of GIT reflog branch switching
git branch branchname HEAD@{1}
Git GC garbage collection
Git remote prune origin synchronizes remote branches and deletes local redundant branches
Git reset — merge cancel merge
git pull –rebase
Git fetch – P clear deleted remote branches
Git log — local history of walk reflogs branchname branch
Git push origin: branchname deletes the remote branch
Git remote show origin view remote branch status
git config –global core. Editor “‘c: \ program files (x86) \ Notepad + + \ Notepad + +. Exe ‘- multiinst – notabbar – nosession – noplugin’ $* ‘” configure the commit editor function
Git log — oneline – 30 merge commit

git在rebase的时候出现
error: The following untracked working tree files would be overwritten by merge:
.idea/workspace.xml
Please move or remove them before you merge.

Use the command: git clean – D – FX to delete some files without git add;
Git clean parameter

-n 显示将要删除的文件和目录;



-x -----删除忽略文件已经对git来说不识别的文件



-d -----删除未被添加到git的路径中的文件



-f -----强制运行

Git cherry pick ID moves the submission information of other branches to the current branch

查询文件权限:
git ls-tree HEAD
git权限修改:
git update-index –chmod=+x filename

Associate other branches:
Git branch — set upstream to = origin / branch name

修改commit信息
git commit –amend

Synchronize remote branch to local
git fetch

Rollback to specified commit
Git reset submission ID

Rollback to previous commit
git reset –hard HEAD

Merge submission information
Git rebase – I submit ID

Cache current changes
git stash

View current cache
git stash list

Release current cache to current branch
git stash pop

Git conflict resolution

  • 切分支到版本主分支 git checkout dev-nta2.0.8 && git pull
  • git rebase dev-nta2. 0.8 & & conflict resolution (the conflict is resolved one file at a time, which means that step 3 must be performed once to resolve a conflict file)
    3 . Resolve conflict file & & git status & & git add conflict_ file && git rebase –continue
  • Repeat step 3 above until all conflicting files are resolved
  • git push origin your_branch

Git garbage cleaning solution:
1. Enter the command: git fsck — lost found, and you can see a lot of “dangling commit”
2. Empty them: git GC — prune = now, done

Windows supports long paths, otherwise an error will be reported if the code path is too long

git config –global core.longpaths true

Windows Downloads git code by default, and the link attribute is not displayed

git config –global core.symlinks true

The code encoding format downloaded by windows will not be converted, and the submission will not be converted (the default installation will be converted to windows)

git config –global core.autocrlf false