git和本地修改 [英] git and local modifications

查看:109
本文介绍了git和本地修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚做了以下测试:


  1. 创建一个文件夹和2个文件

  2. 然后git init,git add。,git commit -m初始提交
  3. 创建一个分支:git branch experimental,git checkout experimental

  4. 然后更改文件夹的名称并删除其中一个文件,然后git add。,git commit -mexperimental
  5. >
  6. 回到master:git checkout master

    惊喜:我离开它时找不到主人;该文件夹已经消失。我不得不做一个git -reset - 很难找到我的文件夹。



    我在想我是否做错了什么,或者我不明白git如何管理本地更改。

详细方案:

  mkdir GitTest 
cd GitTest /
mkdir Folder1
echomaster> Folder1 / File1.txt
echomaster> File2.txt
git init
git add。
git commit -minit
git branch ex
git checkout ex
mv File2.txt File3.txt
mv Folder1 / Folder1-exp /
echoexpe>> Folder1-exp / File1.txt
git add。
git commit -mexpe
git checkout master
ls
git checkout ex
ls


解决方案

这可能是因为 git add。 git add -A

只有git add -A会记录新文件被删除的文件。

>

当你完成你的第二个 git add。时,这里是 git status 不得不说:

  C:\HOMEWARE\git\tests\p2> git status 
#在分支上exp
#要提交的更改:
#(使用git reset HEAD< file> ...来暂停)

#new file:f2 /f1b.txt

#已更改但未更新:
#(使用git add / rm< file> ...来更新将提交的内容)
#(使用git checkout - < file> ...放弃工作中的更改目录)

#已删除:f1 / f1a.txt
#已删除:f1 / f1b.txt

工作树删除了第一个目录。



所以当你切换回主人时,被保留:

  C:\HOMEWARE\git\tests\p2> git checkout master 
D f1 / f1a.txt
D f1 / f1b.txt
转换到分支'master'

因此' f1 '...


的消失

I am discovering how to use git.

I just made the following test:

  1. create a folder and 2 files
  2. then git init, git add ., git commit -m "initial commit"
  3. create a branch: git branch experimental, git checkout experimental
  4. then change the name of the folder and delete one of the files, then git add ., git commit -m "experimental"
  5. go back to master: git checkout master

    Surprise: I do not find the master as I left it; the folder has disappeared. And I have to do a git -reset --hard to find my folder.

    I wonder if I did something wrong or if I have not understood how git manages local changes. Thanks for your help.

Detailed scenario:

mkdir GitTest
cd GitTest/
mkdir Folder1
echo "master" > Folder1/File1.txt
echo "master" > File2.txt
git init
git add .
git commit -m "init"
git branch expe
git checkout expe
mv File2.txt File3.txt 
mv Folder1/ Folder1-exp/
echo "expe" >> Folder1-exp/File1.txt 
git add .  
git commit -m "expe"
git checkout master
ls
git checkout expe
ls

解决方案

That would be because of the difference between git add . and git add -A.

Only git add -A will record new files and deleted files.

When you did your second git add ., here what git status had to say:

C:\HOMEWARE\git\tests\p2>git status
# On branch exp
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   f2/f1b.txt
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    f1/f1a.txt
#       deleted:    f1/f1b.txt
#

The working tree had the first directory deleted.

So when you switched back to master, that working tree was preserved:

C:\HOMEWARE\git\tests\p2>git checkout master
D       f1/f1a.txt
D       f1/f1b.txt
Switched to branch 'master'

Hence the disappearance of 'f1'...

这篇关于git和本地修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆