Code Monkey home page Code Monkey logo

Comments (9)

nicejade avatar nicejade commented on June 18, 2024 1

如何删除 Git 仓库所有提交历史记录

删除 .git 文件夹可能会导致您的 git 存储库中的问题。如果要删除所有提交历史记录,但将代码保持在当前状态,则执行以下操作非常安全:

1, Checkout

git checkout --orphan latest_branch

2, Add all the files

git add -A

3, Commit the changes

git commit -am "commit message"

4, Delete the branch

git branch -D master

5, Rename the current branch to master

git branch -m master

6, Finally, force update your repository

git push -f origin master

PS:这不会保留你的旧的提交历史; 详情参见 how to delete all commit history in github? [duplicate]

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

Problem:You have not concluded your merge (MERGE_HEAD exists)
Solve:

git merge --abort [Since git version 1.7.4]
git reset --merge [prior git versions]

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

git 如何删除本地所有未提交的更改?

如果所有更改,没有加入暂存区的话,可以:

git checkout . && git clean -xdf

如果你有的修改以及加入暂存区的话,那么 :

git reset --hard 
git clean -xdf 

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

Mac必备软件渐集之ZSH-终极Shell 一文的评论 issues37 中有强求的推荐使用 oh-my-zsh;
如果您使用了她,那么这份 git.plugin.zsh 配置, 对你来说,肯定也会是让你欣喜的礼物 ✔️

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

Git 取消修改,恢复版本 命令大全

取消对文件的修改。还原到最近的版本,废弃本地做的修改。

git checkout --

取消已经暂存的文件。即,撤销先前"git add"的操作

git reset HEAD ...

修改最后一次提交。用于修改上一次的提交信息,或漏提交文件等情况。

git commit --amend

回退所有内容到上一个版本

git reset HEAD^

回退 xx.py 这个文件的版本到上一个版本

git reset HEAD^ xx.py

向前回退到第 3 个版本

git reset –soft HEAD~3

将本地的状态回退到和远程的一样

git reset –hard origin/master

回退到某个版本

git reset 057d

回退到上一次提交的状态,按照某一次的commit完全反向的进行一次commit.(代码回滚到上个版本,并提交git)

git revert HEAD

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

Git 同时 push 到多个仓库(同步)

为防止一个git仓库由于各种原因造成无法访问,可以将代码push到多个仓库。编辑本地仓库目录下面的 .git 目录下的 config 文件(命令:vim ./git/config)。添加类如以下命令:

[remote "all"]
url = [email protected]:licess/licess.git
url = [email protected]:licess/licess.git

再 push 时,运行如下命令即可:

git push all master

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

如何切换多个 GitHub 账号

Git 共有三个级别的 config文 件,分别是 system、global和 local。可以使用 git config --list | grep user (windows 需用 sls 替换 grep)来查看配置;当 git commit 时,Author 信息依次读取local、global和system的配置,如果找到则不再继续读取。其他配置的读取顺序也是如此。更改配置可运行:git config --local user.name your-name ,更多详情可查看 这里

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

Git 删除某次错误的提交以及记录?

git reset --hard <commit_id>
git push origin HEAD --force

from jadeblog-backups.

nicejade avatar nicejade commented on June 18, 2024

从存储库中删除敏感数据

git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "your-secret-email" ];
then
        GIT_AUTHOR_NAME="your-can-be-known-name";
        GIT_AUTHOR_EMAIL="your-can-be-known-email";
        GIT_COMMITTER_NAME="your-can-be-known-name";
        GIT_COMMITTER_EMAIL="your-can-be-known-email";
        git commit-tree "$@";
else
        git commit-tree "$@";
fi' HEAD

具体可参见:Removing sensitive data from a repository

from jadeblog-backups.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.