将远程分支硬重置为后面的一些提交

时间:2017-09-19 10:20:21

标签: git

我将本地develop分支重置为后面的几个提交,并希望将本地develop分支推送到其远程,以便远程的HEAD现在也重置为后面的几个提交。 / p>

换句话说,我确实喜欢这样:

UserName path/ (develop)
$ git reset --hard {CommitIdOfAFewCommitsBehind}
Your branch is behind 'origin/develop' by 14 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working tree clean


$ git push origin develop
To https://github.devtools.merrillcorp.com/Javelin/wopi-poc.git
 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://github/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

如何使遥控器也转到我想要的提交ID?

1 个答案:

答案 0 :(得分:3)

当您对 public void Import_CSV() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "CSV Files (*.csv)|*.csv"; bool? result = dialog.ShowDialog(); if (result ?? false) { string[] headers; string CSVFilePathName = dialog.FileName; string delimSelect = cboDelimiter.Items.GetItemAt(cboDelimiter.SelectedIndex).ToString(); // If user hasn't selected a delimiter, assume comma if (delimSelect == "") { delimSelect = ","; } string[] delimiterType = new string[] {cboDelimiter.Items.GetItemAt(cboDelimiter.SelectedIndex).ToString()}; DataTable dt = new DataTable(); // Read first line of file to get number of fields and create columns and column numbers in data table using (StreamReader sr1 = new StreamReader(CSVFilePathName)) { headers = sr1.ReadLine().Split(delimiterType, StringSplitOptions.None); //dt.Columns.Add("ROW", typeof(int)); //dt.Columns["ROW"].AutoIncrement = true; //dt.Columns["ROW"].AutoIncrementSeed = 1; //dt.Columns["ROW"].AutoIncrementStep = 1; int colCount = 1; foreach (string header in headers) { dt.Columns.Add("C" + colCount.ToString()); colCount++; } } using (StreamReader sr = new StreamReader(CSVFilePathName)) { while (!sr.EndOfStream) { string[] rows = sr.ReadLine().Split(delimiterType, StringSplitOptions.None); DataRow dr = dt.NewRow(); for (int i = 0; i < headers.Length; i++) { dr[i] = rows[i]; } dt.Rows.Add(dr); } } dtGrid.ItemsSource = dt.DefaultView; txtColCount.Text = dtGrid.Columns.Count.ToString(); txtRowCount.Text = dtGrid.Items.Count.ToString(); } } 分支进行硬重置时,您重写了该分支的历史记录。这个的一个副作用(后面讨论的另一个副作用)是Git不再只是接受你的推送,因为它不知道如何将你的新截断分支与远程版本相关联。所以,你需要强制推送覆盖:

develop

我提到了另一个副作用,即重写git push --force origin develop 的历史记录也会给团队中的其他人带来问题,当他们拉动时,他们恰好分享了这个分支。

大多数情况下,对于共享分支,最好使用硬复位执行develop而不是nuking提交。查看文档或Stack Overflow以了解如何还原一系列提交。