我使用git bash运行的最后一条命令导致.css文件的内容被完全删除..该文件仍然在那里只是空的。我是git的新手,不知道发生了什么事。
我的所有命令都在这里:
git branch modify
git checkout modify
git status
git add .
git commit -a -m "my message"
git push origin modify
git push origin master
git push origin master
git branch -D contact_nav
我不知道为什么我要先修改然后再修改两次,我认为那可能是哪里出了问题。
我没有备份提交,这是我对文件进行所有更改之后的第一次提交。只有css消失了,我的html和javascript及其所有新更改仍然存在。
答案 0 :(得分:0)
如果该文件在该分支中为空,则第一个命令git checkout Modify可能会覆盖.css文件内容。
您的其他文件(如果是私有文件且未在该分支中进行版本控制)将被checkout命令忽略:它们将按原样保留在工作树中,准备好进行添加和提交。
问题是:如果从未将css内容至少添加到索引中,则该内容将丢失,除非您的编辑器/ IDE将其包含在其自己的本地历史记录中。
答案 1 :(得分:0)
reflog中没有任何内容?
$ git reflog | grep contact_nav
答案 2 :(得分:0)
以下是Git将使用您的命令执行的操作序列:
git branch modify
#Create a branch 'modify'
git checkout modify
#Chekout to branch 'modify'
git status
#See the status of changed files since your last pull or clone
git add .
#add all the changed files in your current directory to the staging area. Now Git
#starts tracking these files.
git commit -a -m "my message"
#Commit the tracking area changes and give it a revision (SHA1). Here -a is not needed because you have already run git add command.
git push origin modify
#Push to modify. This will push all the changes from the staging area to branch modify.
git push origin master
#Now you are trying to push your changes to the master branch. However, since the changes
#are already pushed to the staging area, there is no new change to push to master.
git push origin master
#Same as the previous command
git branch -D contact_nav
#Now you are force deleting branch 'contact_nav'
要使css文件恢复原状,您需要做些什么:
git branch
#This will tell which branch you are in. If it shows 'modify' as green then you are
#in that branch. If not, then use command `git checkout modify`
git log
#Check if it shows your commit with a message "my message" as latest change.
#If you do not see such commit then you made your css change in some different branch. In this case, you need to make those css changes here in this branch. Once you edit the css file, again you need to execute commands
#git add .
#git commit -m "my message"
#git push origin modify
#In case you see your .csv commit then you need to run below command
git reset --hard <SHA1 of your change with commit message "my message">
#This will bring your local to the change where you added content to .csv file.
#And you have your changes back.