Git-提交,分支和合并会带来意想不到的行为

时间:2019-02-26 12:17:19

标签: git visual-studio-code

最近,我开始在公司与Git合作,但我发现有些奇怪的事情,所以我无法弄清楚到底是怎么回事。

因此,对于工作流,我们有一个存储库,并且政策是,每当我们要处理项目时就必须创建一个分支,这很简单,而且很有意义。

我遇到的问题是,当我在分支中完成工作时,我将剩下的一切暂存并推送我的最终提交,然后我创建一个pull请求,并且它必须在合并之前通过代码审查。

但是,当拉取请求被批准并且更改合并到master时,我想在本地删除我的分支(因为无论如何在原点上合并,它都会被自动删除)。实际上,这并不像我期望的那样直接。

发生的事情是,如果我尝试删除我的分支或检出另一个分支,则git会阻止我,因为它希望我知道我未进行提交更改。对于我来说,这是毫无意义的部分,我所做的一切都已提交,审核和合并,那么这些更改是什么?

到目前为止,我所做的是使用“ git add”。现在,我可以检查它,看这里做了什么更改,因为它说其中包含更改。这是第二个奇怪的事情,根本没有任何变化。

因此,我暂时要手动解决这些问题,但是当我必须对每个分支执行此操作时,这将很耗时。我错过了明显的事情吗?我在做错什么吗?

今天再次发生这种情况,虽然略有不同,但最终结果是相同的。我已经完成了一项功能,清理了分支(今天没有问题),所以删除该功能分支时我想做的是检出master并进行更改以确保我使用的是最新版本,然后进行下一步操作。上面写的发生在高手。我进行了所有最新更改,但是git告诉我我未进行暂存更改(检查这些文件时完全没有更改)。

次要更新:git status -u仅表示我的分支与origin / HEAD保持最新,并且我已取消暂存的更改(列出这些文件),仅此而已,再次从Visual隐藏Studio代码更改部分。我唯一的选择是暂存它们(“ git add”,使它们在编辑器中可见)或丢弃它们(git checkout“文件名”)。

gitignore:

# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.sass-cache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
*.sqlite
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk 
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output 
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder 
.mfractor/
/.vscode

1 个答案:

答案 0 :(得分:0)

TL; DR

1)确保在没有git diff-b且没有-w的情况下执行core.autocrlf=false

2)如果您确定没有要提交的进一步更改,则可以使用git reset --hard立即重置所有已更改的文件。

详细信息

差异

git statusgit diff对于要更改的文件有不同意见时,这可能是由于空格问题引起的,尤其是在Windows上,尤其是换行符样式。

例如,我在Windows上进行了此测试:

  • 将文件a从Linux换行符更改为Windows风格的CRLF
  • git statusa已更改(无论core.autocrlf的设置如何)
  • git diff显示acore.autocrlf=false的变化
  • git diff显示core.autocrlf=true时完全没有变化
  • 类似地,git diff -bgit diff -w没有变化。

重置

现在,如果您知道沙箱中的值没有更改,例如,所有更改都是由于行尾引起的,则可以使用以下命令将整个沙箱重置为HEAD中的状态:< / p>

git reset --hard

警告:这是破坏性的,无法撤消。沙盒中文件的所有更改都将永久丢失。