Git - 当分支BranchA时,如何重置我的新分支BranchB,使其没有任何BranchA内容?

时间:2016-02-05 11:31:08

标签: git

我在BranchA上做了很多工作。

我现在想要创建一个新的本地分支BranchB并从GitHub下拉这个远程分支。

但是,执行git checkout -b BranchB仍然会对BranchA进行所有更改。

如何重置此分支以使其中没有任何内容,因此我可以从GitHub中提取干净的BranchB?

感谢。

2 个答案:

答案 0 :(得分:0)

假设BranchB在服务器上,只需:Product: Solar Radio Data 7day_rad.txt :Issued: 0922 UTC 05 Feb 2016 # # Prepared by the U.S. Dept. of Commerce, NOAA, Space Weather Prediction Center # Please send comments and suggestions to SWPC.Webmaster@noaa.gov # Units: 10^-22 W/m^2/Hz # Missing Data: -1 # # Daily local noon solar radio flux values - Updated once an hour # Freq Learmonth San Vito Sag Hill Penticton Penticton Palehua Penticton MHZ 0500 UTC 1200 UTC 1700 UTC 1700 UTC 2000 UTC 2300 UTC 2300 UTC 2016 Jan 30 245 20 17 17 -1 -1 12 -1 410 38 34 37 -1 -1 35 -1 610 56 -1 56 -1 -1 50 -1 1415 104 73 72 -1 -1 78 -1 2695 106 106 98 -1 -1 101 -1 2800 -1 -1 -1 105 105 -1 105 4995 -1 149 134 -1 -1 145 -1 8800 287 269 261 -1 -1 275 -1 15400 514 573 536 -1 -1 515 -1 2016 Jan 31 245 21 18 20 -1 -1 32 -1 410 39 17 38 -1 -1 46 -1 610 58 -1 56 -1 -1 60 -1 1415 91 74 72 -1 -1 78 -1 2695 102 103 97 -1 -1 100 -1 2800 -1 -1 -1 102 101 -1 100 4995 -1 146 135 -1 -1 138 -1 8800 278 268 262 -1 -1 272 -1 15400 513 568 530 -1 -1 521 -1 2016 Feb 1 245 25 21 21 -1 -1 35 -1 410 45 40 40 -1 -1 49 -1 610 66 -1 59 -1 -1 63 -1 1415 65 72 68 -1 -1 78 -1 2695 99 101 90 -1 -1 97 -1 2800 -1 -1 -1 100 100 -1 100 4995 -1 140 131 -1 -1 139 -1 8800 278 258 266 -1 -1 275 -1 15400 508 565 528 -1 -1 526 -1 2016 Feb 2 245 23 20 21 -1 -1 36 -1 410 45 68 40 -1 -1 48 -1 610 68 -1 60 -1 -1 61 -1 1415 72 73 69 -1 -1 80 -1 2695 98 98 93 -1 -1 102 -1 2800 -1 -1 -1 102 102 -1 103 4995 -1 141 131 -1 -1 141 -1 8800 284 255 268 -1 -1 276 -1 15400 510 568 537 -1 -1 526 -1 2016 Feb 3 245 34 -1 20 -1 -1 36 -1 410 47 -1 41 -1 -1 50 -1 610 70 -1 63 -1 -1 66 -1 1415 68 76 76 -1 -1 86 -1 2695 105 -1 106 -1 -1 112 -1 2800 -1 -1 -1 113 112 -1 112 4995 -1 -1 140 -1 -1 152 -1 8800 284 -1 260 -1 -1 284 -1 15400 516 -1 455 -1 -1 535 -1 2016 Feb 4 245 -1 23 21 -1 -1 46 -1 410 -1 43 43 -1 -1 54 -1 610 -1 -1 65 -1 -1 68 -1 1415 -1 84 81 -1 -1 90 -1 2695 -1 114 120 -1 -1 118 -1 2800 -1 -1 -1 125 123 -1 120 4995 -1 162 154 -1 -1 158 -1 8800 -1 276 273 -1 -1 283 -1 15400 -1 564 523 -1 -1 547 -1 2016 Feb 5 245 34 -1 -1 -1 -1 -1 -1 410 52 -1 -1 -1 -1 -1 -1 610 78 -1 -1 -1 -1 -1 -1 1415 84 -1 -1 -1 -1 -1 -1 2695 115 -1 -1 -1 -1 -1 -1 2800 -1 -1 -1 -1 -1 -1 -1 4995 -1 -1 -1 -1 -1 -1 -1 8800 295 -1 -1 -1 -1 -1 -1 15400 508 -1 -1 -1 -1 -1 -1 (没有git checkout BranchB选项)。这将创建BranchB并让它自动跟踪origin / BranchB。如果您已在本地创建了“错误的”BranchB,请务必先使用-b将其删除。

答案 1 :(得分:0)

您可以使用以下命令创建从历史记录的某个点开始的分支:

git checkout -b BranchB <sha1>

这个命令可以做两件事:

  • 它创建一个名为BranchB的本地分支,它从&lt; sha1&gt;
  • 开始
  • HEAD使用您的工作树切换到此分支

然后你可以推送和跟踪它:

git push origin BranchB --set-upstream

请注意&lt; sha1&gt;可能是:

  • 起源/主
  • 起源/主〜1
  • BranchA〜2
  • 实际上,任何提交的sha1

如果你已经有一个&#34;坏&#34;名为BranchB的本地或远程分支,您可以删除它们:

git push origin :BranchB  # Deletes the remote branch origin/BranchB
git branch -d BranchB     # Deletes the local branch BranchB (if merged, no risk to loose data)
git branch -D BranchB     # Deletes the local branch BranchB (force for not merged branches)