[git] summary

Table of contents

branch operation

Inquire

warehouse operations

version changes

pull request

Compare the differences between different branches, and copy the file from branch A to branch B

How to keep the fork warehouse on github synchronized with the original warehouse



branch operation

# 关联远程分支,关联之后可以直接git pull/git push
git branch --set-upstream-to=<仓库名>/<分支名>

# 查看分支关联情况
git branch -vv

# branch重命名
git branch -m oldName  newName

# 查看所有分支
git branch -a
 
# 删除远程分支
git push origin --delete 远程分支

# 拷贝指定仓库的指定分支
git remote add upstream xxx.git
git fetch upstream
git checkout -b test remotes/upstream/specified_branch

Inquire

# commit的提交记录
git log 

# commit的提交记录+改动细节
git log -p

# commit的提交记录+改动大致内容
git log --stat

# 对比工作目录和缓存区的不同
git diff

warehouse operations

# git clone specified tag
git clone -b version link.git


# ------------- 查看配置信息
git config --global -l  # 全局配置
git config --local -l   # 本地仓库配置

# ------------- 修改仓库配置信息
# 方式1
vim ../.git/config

#方式2
git config --local -e

#方式3
git config --local user.name xxx
git config --local user.email 'xxx'

# 参考:https://www.runoob.com/git/git-remote.html
# 查看远程仓库
git remote -v

# 显示某个仓库的信息
git remote show origin

# 添加本地版本库
git remote add  [shortname] [url(.git)]

# 从指定远程仓库拉取代码
git fetch [shortname]

# 将shortname仓库的所有变更合并到本地,如果本地clone的是fork的仓库,后面就可以推送到fork的仓库中了
git merge [shortname]/develop

# 删除远程仓库
git remote rm  [shortname]

# 修改仓库名
git remote rename old_name new_name

version changes

# 提交之后发现漏掉部分文件没有添加
git commit -m "v1"
git add test.txt
git commit --amend  # 将代替上一次提交的结果

# 版本倒退
git reset --hard <commit_id>


# 取消暂存的文件,文件的修改仍保留
git add test.txt
git reset HEAD test.txt


# 撤销对文件的修改
git checkout -- test.txt

pull request

# 克隆仓库代码
git clone https://xxx.git
 
# 建立并切换到分支
git checkout -b xxx
 
# 修改代码
 
# 查看修改文件
git stutas
 
 
# 将全部文件添加到暂存区,也可以指定文件
git add .
# 将untrack file清理掉
git clean -nf
git clean -f
 
# git第一次提交的时候,要配置用户名和邮箱
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
 
# 将本地暂存的修改提交到版本库
git commit -m "xxx"
 
# 代码合并
git checkout master
git pull
git checkout xxx
 
git rebase master
 
# 查询文件冲突
git status 
 
# 手动修改冲突
 
# 将修改的文件添加在缓冲区
git add xx
# 添加已修改的(新增或修改)内容至暂存区(不含删除的文件)
git add . 
# 添加本地所有修改的内容至暂存区(包含删除的文件)
git add -A
 
git rebase --continue  # 修改成功,继续
git rebase --abort     # 修改失败,停止修改,重新git rebase develop
 
# 提交到远程仓库
git push origin 本地分支名:远程分支名

Compare the differences between different branches, and copy the file from branch A to branch B

# compare
git diff branch_A branch_B --stat

# 将branch_A中的文件file移植到 branch_B
git checkout branch_B
git checkout --patch branch_A file_path

How to keep the fork warehouse on github synchronized with the original warehouse

 How to keep the fork project on github synchronized with the original project Follow a certain project, usually use star, and occasionally fork it, go to the personal project library, study the code, and hope to have the opportunity to contribute code. As a technical novice, now you will encounter code that has been forked. The original project may be updated, but the project under the personal account cannot be updated synchronously. This is definitely not conducive to our study. Synchronization project Search the Internet for how to synchronize the fork project and the original project, and many enthusiastic netizens have various solutions. Delete the original project and re-fork https://blog.csdn.net/binglumeng/article/details/59534975?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~ Rate-1.pc_relevant_paycolumn_v3&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1.pc_relevant_paycolumn_v3&utm_relevant_index=1

Git remote: error : this exceeds file size limit of 100.0 MB After getting rid of the above error, after deleting it locally, the same error will still be reported, indicating that it has been saved in a git cache, and can be modified as follows: For example, the large file I deleted before is a.txt (the folder is the same), execute The following code can delete it in a git buffer git filter-branch -f --prune-empty --index-filter 'git rm -... https://blog.csdn.net/bigsungod/article/details /83994199

Git adds files that have been submitted to .gitignore - Take a look at the files that git has submitted before. During the development process, this file needs to be ignored and added to .gitignore, but when it is submitted again, the file is still tracked. The solution is as follows: In order to avoid conflicts, first pull the remote warehouse to the local git pull http://t.zoukankan.com/chengfengchi-p-14814728.html

Adding, using and deleting submodule submodules in git_guotianqing's blog-CSDN blog_submodule Background projects often use modules maintained by others, and using the function of submodules in git can greatly improve development efficiency. After using the submodule, you don't have to be responsible for the maintenance of the submodule, you only need to update the submodule synchronously when necessary. This article mainly explains the basic commands related to submodules. For detailed usage, please refer to the man page. Adding submodules Adding submodules is very simple, the command is as follows: git submodule add &lt;url&gt; &lt;path&gt; Among them, url is the submodule... https://blog.csdn.net /guotianqing/article/details/82391665?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-82391665-blog-109540174.p c_relevant_multi_platform_whitelistv1_exp2&depth_1-utm_source=distribute.pc_relevant_t0 .none-task-blog-2~default~CTRLIST~default-1-82391665-blog-109540174.pc_relevant_multi_platform_whitelistv1_exp2&utm_relevant_index=1

Guess you like

Origin blog.csdn.net/zmj1582188592/article/details/123529220