我意外地在master
而不是mybranch
分支中添加并编辑了文件。现在,即使我切换到mybranch
我也无法通过git status
看到它。如何在mybranch
中添加/提交和重新添加该文件?
答案 0 :(得分:1)
您可以在mybranch
首先,修复master
分支
git checkout master
git branch tmp // This creates a branch in the "wrong" commit
git reset --hard HEAD~1
您将master
分支移回一个提交。你仍然有一个指向你的提交的时间分支。
现在,将提交移至mybranch
分支
git checkout tmp
git rebase --onto mybranch master tmp
git checkout mybranch
git merge tmp
git branch -d tmp
rebase命令:
我建议你打开一些前端,看看你在做什么。我使用gitk
gitk --all &
答案 1 :(得分:0)
在主分支中使用git rm dir1/dir2/file
。在正确的分支中使用git show master:dir1/dir2/file >dir1/dir2/file
和git add dir1/dir2/file
如果您在错误提交后更新了主分支,当然您无法在master
命令中使用git show
来恢复文件。您可以使用git reflog
查找合适的参考。如果它恰好是HEAD@{2}
,则命令将为git show HEAD@{2}:dir1/dir2/file >dir1/dir2/file
(git会自动识别它是相同的文件内容,因此您不必担心双磁盘空间消耗。)
答案 2 :(得分:0)
详细答案为here。您可以使用var app = angular.module('TestApp',[]);
app.controller('TestController', function($scope)
{
$scope.nameSearch = {};
$scope.nameSearch.position = 'All';
$scope.positions = ['All','QB','RB','WR','TE','DEF','K'];
$scope.players = $scope.allPlayers;
$scope.setPosition = function()
{
$scope.players = [];
if ($scope.nameSearch.position != 'All')
{
for (var i in $scope.allPlayers) if ($scope.allPlayers[i].Position == $scope.nameSearch.position) $scope.players.push($scope.allPlayers[i]);
return;
}
$scope.players = $scope.allPlayers;
};
$scope.allPlayers = [
{
"Rank":1,
"First":"Le'Veon",
"Last":"Bell",
"Position":"RB",
"Team":"PIT",
"Bye Week":11
},
{
"Rank":2,
"First":"Jamaal",
"Last":"Charles",
"Position":"RB",
"Team":"KC",
"Bye Week":9
},
{
"Rank":3,
"First":"Adrian",
"Last":"Peterson",
"Position":"RB",
"Team":"MIN",
"Bye Week":5
}...
...
..
...];
$scope.setPosition();
});
或rebase -onto
。至于我 - 我更喜欢cherry-pick
。