使用git reset命令重置错误本地提交

目录

问题

1. 使用git log回退到最近提交的版本

2. 回退到版本

3. 修改gitignore文件提交


问题

应该是困扰了很久,gitignore没提前配置好,或者是有些文件没有忽略就git add。

使用git rm –cached . 能删除暂缓区文件,但是重新push一次还是会有先前的文件。

git rm –cached . 


这里我的解决·办法是版本回退:

1. 使用git log回退到最近提交的版本

git log

 

2. 回退到版本

git reset --soft cf9b9e5058412c56279f02c7b0ea314c81e92000


3. 修改gitignore文件提交

这里我的gitignore文件更新后加上

*.tar.gz
*.gz
*.bin
*.zip


完整 .gitignore
 


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
 
# C extensions
*.so
 
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
 
# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
 
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
 
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
 
# Translations
*.mo
*.pot
 
# Django stuff:
*.log
local_settings.py
db.sqlite3
 
# Flask stuff:
instance/
.webassets-cache
 
# Scrapy stuff:
.scrapy
 
# Sphinx documentation
docs/_build/
 
# PyBuilder
target/
 
# Jupyter Notebook
.ipynb_checkpoints
 
# IPython
profile_default/
ipython_config.py
 
# pyenv
.python-version
 
# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don’t work, or not
#   install all needed dependencies.
#Pipfile.lock
 
# celery beat schedule file
celerybeat-schedule
 
# SageMath parsed files
*.sage.py
 
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
 
# Spyder project settings
.spyderproject
.spyproject
 
# Rope project settings
.ropeproject
 
# mkdocs documentation
/site
 
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
 
# Pyre type checker
.pyre/
 
*.tar.gz
*.gz
*.bin
*.zip
发布了83 篇原创文章 · 获赞 27 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weweeeeeeee/article/details/103160337