Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 1.95 KB

git-usage.org

File metadata and controls

72 lines (56 loc) · 1.95 KB

Appendix

How to add a branch that is in the upstream repo but not in your forked repo?

  1. Add osc2023 as the upstream
    git remote add -t <your student id> upstream https://github.com/oscapstone/osc2023.git
    git fetch upstream
        
  2. Checkout your branch from the upstream
    git checkout -b <local branch name> upstream/<your student id>
        
  3. Push the branch to your forked repo
    git push -u origin <local branch name>
        

How to remove a file from the git history?

Warning: If you not no fully understand what are you doing, please backup the repo. TAs are not responsible for any mistake in this section or any damage produced by your git operations. If you need to modify the history that has been merged into the upstream repo, please contact with TA.

case 1: the file is added in the latest commit

Just modify the latest commit

git rm --cached <filename>
git commit --amend -C HEAD

What if you have pushed to Github? Force push again.

git push -f origin <your student id>

case 2: the file is added in a old history.

I suggest that you use git rebase to modify the history. First, use git log to find the commit you added the file. Suppose the commit id is 7a45f90. Use the commit before 7a45f90 as the newbase.

git rebase -i 7a45f90^

This command pops up the editor. Modify pick 7a45f90 to edit 7a45f90, then save and close the editor.

git rm --cached <filename>
git commit --amend

Repeatedly use the following command until the rebase procedure finished.

git rebase --continue
# if there is conflict
git rm <filename>

You might need to force push to the github repo.

Warning: force push is not revertable.

git push -f origin