【问题标题】:Move local uncommitted changes to new branch [duplicate]将本地未提交的更改移动到新分支[重复]
【发布时间】:2020-07-28 10:01:53
【问题描述】:

我有未提交的本地更改。我想创建一个新分支并将更改移到那里。

我的理解正确吗?我应该这样做:

git diff > my_work.txt
git checkout -b new_branch_name
git push origin new_branch_name
git apply my_work.txt

【问题讨论】:

    标签: git


    【解决方案1】:

    你可以使用git stash:

    存储您的更改(包括未跟踪的文件)

    git stash push --include-untracked
    

    用 git status 验证干净的工作目录

    git status
    

    检查您的分支

    git checkout <MyFancyBranch>
    

    将隐藏的更改应用到当前分支

    git stash pop
    

    【讨论】:

      【解决方案2】:

      git stash 让这件事变得简单一些。

      $ git stash
      $ git stash branch new_branch_name
      

      这将在创建和签出新分支之前保留暂存的未暂存的更改。

      【讨论】:

        猜你喜欢
        • 2012-11-21
        • 1970-01-01
        • 2021-05-01
        • 2020-12-13
        • 1970-01-01
        • 2019-07-28
        • 1970-01-01
        • 2016-06-12
        • 2022-08-18
        相关资源
        最近更新 更多