Git结帐不会改变任何东西 [英] Git checkout does not change anything

查看:83
本文介绍了Git结帐不会改变任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢git。至少,我喜欢git的想法。能够检查我的主项目作为一个单独的分支,我可以改变我想要的任何东西,而不用担心把所有事情都搞砸了,这真是太棒了。基本上,我的工作流程如下所示:


  1. 签出稳定的版本到新的分支来试验新的代码

  2. 进行一系列更改 - 我无意保留任何内容,只是试验。 b $ b
  3. 查看所有我更改的内容

  4. 添加所有要跟踪的更改

  5. 提交分支并将分支推送到原点(如果有效,则跳过此步骤)

  6. 决定尝试另一种方法,返回主页

  7. 观察实验中的人为因素分支我工作,即使我在主分支。

每次我签出一个分支到另一个分支,对一个分支进行更改,然后签出原始分支,我仍然拥有其他分支中发生的所有文件和更改。这变得非常令人沮丧。我读过这样的情况,当你在IDE中打开文件时会发生这种情况,但我一直非常小心,并关闭了IDE中的文件,关闭了IDE,并在切换之前关闭了我的rails服务器分支机构,这仍然发生。另外,运行'git clean -f'可以删除任意提交后发生的所有事情(并且随机发生),或者像最新情况一样,不会将任何事情改回原始状态。

我以为我正确地使用了git,但在这一点上,我在我的机智终结了。我正在尝试使用我的项目的稳定版本来处理大量实验性代码,但我一直不得不手动追踪并修复所做的所有更改。任何想法或建议?

  git checkout -b photo_tagging 
git branch#确保它是正确的
#做一堆更改,创作等
git status#查看自
git add之前发生的变化。 #我认为,如果我在这之后做了git commit,我认为这样做是没有变化的
git commit -m'这些是我做的更改'

git checkout master
git branch#=> * master

#查看文件,tags_controller仍然存在,添加在photo_tagging
#中,并且在photo_tagging分支中添加的代码仍然存在于* master


无论我是否在分支上执行提交,这似乎都会发生。

解决方案

下面是一个如何使用git和分支的例子。

  $ git branch 
* master
组织

$ git分支网络
$ git结帐网络

$ git分支
主人
*网络
组织

现在Master已经更新了很多次,因为任何人在网络上都做了什么

  $ git pull来源网络
从github.com:dlundquist/Asteroids
*分支网络 - > FETCH_HEAD
CONFLICT(重命名/删除):在92d5b7c4e7c4110803eabf5d5152e7f2a337d722中重命名src / ServerClientThread.java-> src / ServerConnectionThread.java并在HEAD
中删除自动合并src / Actor.java
Auto-合并src / Asteroids.java
CONFLICT(内容):在src / Asteroids.java中合并冲突
自动合并src / BasicWeapon.java
CONFLICT(内容):合并src / BasicWeapon中的冲突.java
CONFLICT(删除/修改):src / DedicatedServer.java在HEAD中删除并在92d5b7c4e7c4110803eabf5d5152e7f2a337d722中修改。 src / DedicatedServer.java的版本92d5b7c4e7c4110803eabf5d5152e7f2a337d722留在树中。
自动合并src / MainMenu.java
CONFLICT(内容):在src / MainMenu.java中合并冲突
CONFLICT(删除/修改):src / NetworkClientThread.java在HEAD中被删除并被修改在92d5b7c4e7c4110803eabf5d5152e7f2a337d722。 src / NetworkClientThread.java的版本92d5b7c4e7c4110803eabf5d5152e7f2a337d722留在树中。
CONFLICT(删除/修改):在HEAD中删除src / NetworkUpdate.java并在92d5b7c4e7c4110803eabf5d5152e7f2a337d722中修改。 src / NetworkUpdate.java的版本92d5b7c4e7c4110803eabf5d5152e7f2a337d722留在树中。
自动合并src / ScenePanel.java
CONFLICT(内容):在src / ScenePanel.java中合并冲突
自动合并src / Shield.java
CONFLICT(内容):在src / Shield.java中合并冲突
自动合并src / Sprite.java
自动合并src / TripleShotWeapon.java
自动合并src / Weapon.java
自动合并失败;修复冲突,然后提交结果。
mjolnir:小行星Durandal $ git status
#分支网络
#要提交的更改:

#修改:src / Actor.java
#modified:src / Sprite.java
#modified:src / TripleShotWeapon.java
#modified:src / Weapon.java

#未合并路径:
# (根据需要使用git add / rm< file> ...来标记分辨率)

#修改:src / Asteroids.java
#修改:src / BasicWeapon .java
#被我们删除:src / DedicatedServer.java
#同时修改:src / MainMenu.java
#被我们删除:src / NetworkClientThread.java
#删除us:src / NetworkUpdate.java
#同时修改:src / ScenePanel.java
#由它们添加:src / ServerConnectionThread.java
#两者修改:src / Shield.java

Woah,git真的很疯狂。它看起来像师父是超前网络git为我做所有的工作。

  $ git reset --hard网络
HEAD现在在20d6ee8做主要分支的调整游戏。修复了TripleShotWeapon的一些错误。重新平衡小行星中的gameMechanics()以随着关卡的增加而增加难度。
mjolnir:小行星Durandal $ git status
#分支网络
无需提交(工作目录清理)

好吧,现在我在网络上次推送到原点时回到了时间上。但在我做任何工作之前,我真的应该回去并与师父合并。合并文件花费的时间



<$>
$ b

$ b $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ git分支
* master
联网
组织

现在让我们应用我们的变化。

  $ git合并网络
已经是最新的。

如果您喜欢是啊!,您可能需要这样做。

  $ git合并源网络
已经是最新的。 Yeeah!

将我们的变化推向世界

  $ git push origin master 


I really like git. At least, I like the idea of git. Being able to checkout my master project as a separate branch where I can change whatever I want without risk of screwing everything else up is awesome. But it's not working.

Basically, my workflow is like this:

  1. Checkout stable version to a new branch to experiment with new code
  2. Make a bunch of changes - I have no intent on keeping any of this, I'm just experimenting.
  3. Look at all the stuff I changed
  4. Add all the changes to be tracked
  5. Commit the branch and push branch to origin (if it worked, otherwise skip this step)
  6. Decide to try another method, go back to master
  7. Observe artifacts from the experimental branch I was working in, even though I'm in the master branch.

Every time I checkout a branch to another branch, make changes to the one branch, and then checkout the original branch, I still have all the files and changes that happened in the other branch. This is getting extremely frustrating. I've read that this can happen when you have files open in the IDE while doing this, but I've been pretty careful about that and both closed the files in the IDE, closed the IDE, and shut down my rails server before switching branches, and this still happens. Also, running 'git clean -f' either deletes everything that happened after some arbitrary commit (and randomly, at that), or, as in the latest case, didn't change anything back to its original state.

I thought I was using git correctly, but at this point, I'm at my wit's end here. I'm trying to work with a bunch of experimental code using a stable version of my project, but I keep having to manually track down and fix all the changes I made. Any ideas or suggestions?

git checkout -b photo_tagging
git branch # to make sure it's right
# make a bunch of changes, creations, etc
git status # see what's changed since before
git add . # approve of the changes, I guess, since if I do git commit after this, it says no changes
git commit -m 'these are changes I made'

git checkout master
git branch #=> *master

# look at files, tags_controller is still there, added in photo_tagging
# and code added in photo_tagging branch are still there in *master

This seems to happen whether I do a commit or not on the branch.

解决方案

Here is an example of how to use git and branches.

$ git branch
* master
  organize

$ git branch networking
$ git checkout networking

$ git branch
  master
* networking
  organize

Now Master has been updated many times since anyone has done anything on networking

$ git pull origin networking
From github.com:dlundquist/Asteroids
 * branch            networking -> FETCH_HEAD
CONFLICT (rename/delete): Rename src/ServerClientThread.java->src/ServerConnectionThread.java in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 and deleted in HEAD
Auto-merging src/Actor.java
Auto-merging src/Asteroids.java
CONFLICT (content): Merge conflict in src/Asteroids.java
Auto-merging src/BasicWeapon.java
CONFLICT (content): Merge conflict in src/BasicWeapon.java
CONFLICT (delete/modify): src/DedicatedServer.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/DedicatedServer.java left in tree.
Auto-merging src/MainMenu.java
CONFLICT (content): Merge conflict in src/MainMenu.java
CONFLICT (delete/modify): src/NetworkClientThread.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/NetworkClientThread.java left in tree.
CONFLICT (delete/modify): src/NetworkUpdate.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/NetworkUpdate.java left in tree.
Auto-merging src/ScenePanel.java
CONFLICT (content): Merge conflict in src/ScenePanel.java
Auto-merging src/Shield.java
CONFLICT (content): Merge conflict in src/Shield.java
Auto-merging src/Sprite.java
Auto-merging src/TripleShotWeapon.java
Auto-merging src/Weapon.java
Automatic merge failed; fix conflicts and then commit the result.
mjolnir:Asteroids Durandal$ git status
# On branch networking
# Changes to be committed:
#
#   modified:   src/Actor.java
#   modified:   src/Sprite.java
#   modified:   src/TripleShotWeapon.java
#   modified:   src/Weapon.java
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      src/Asteroids.java
#   both modified:      src/BasicWeapon.java
#   deleted by us:      src/DedicatedServer.java
#   both modified:      src/MainMenu.java
#   deleted by us:      src/NetworkClientThread.java
#   deleted by us:      src/NetworkUpdate.java
#   both modified:      src/ScenePanel.java
#   added by them:      src/ServerConnectionThread.java
#   both modified:      src/Shield.java

Woah, git is really mad. It looks like Master is too far ahead of Networking for git to do all the work for me.

$ git reset --hard networking
HEAD is now at 20d6ee8 done tweaking game on the main branch.  Fixed a few bugs with the TripleShotWeapon.  Rebalanced the gameMechanics() in Asteroids to increase the difficulty as the levels increase.
mjolnir:Asteroids Durandal$ git status
# On branch networking
nothing to commit (working directory clean)

Ok, now I am "back in time" when networking last pushed to origin. But I really should go back and merge with Master now before I do any work. Other wise it will be even hard to merge.

Time spent merging files

$ git add (insert conflict resolved files here)
$ git commit -a -m "Merged networking with master"
$ git checkout master
$ git branch
* master
  networking
  organize

Now lets apply our changes.

$ git merge networking
Already up-to-date.

You might want to do this if you like the "Yeah!"

$ git merge origin networking
Already up-to-date. Yeeah!

Push our changes to the world

$ git push origin master

这篇关于Git结帐不会改变任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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